How to get path of current target file using NLog in runtime?

前端 未结 4 1711
猫巷女王i
猫巷女王i 2021-01-31 07:36

I use NLog with next configuration:

  
    

        
4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-31 08:17

    Targets can be wrapped multiple times (in my case I had a filter), so the following snippet is a more generic approach to unwrapping that works for multiple levels and doesn't make assumptions about target names.

    Target target = LogManager.Configuration.FindTargetByName(targetName);
    while ((target != null) && (target is WrapperTargetBase))
    {
        target = (target as WrapperTargetBase).WrappedTarget;
    }
    

提交回复
热议问题