我有一个包含路径的 static
字段的类。
public static class PfadSammlung
{
public static string Path_Example = @"C:\temp";
}
如何在 NLog.Config
文件中使用此路径来指定目标的文件名?
<targets>
<target xsi:type="File"
name ="processInfo"
fileName="C:\temp\ProcessInfoLog.log"
layout="${longdate} | ProcessInfo: ${message}"
/>
</targets>
如有任何帮助,我们将不胜感激。
最佳答案
基本上,您需要从代码中配置 NLog。查看offical documentation有关详细信息和示例代码。
更新
正如 Julian 所指出的,您还可以在配置 XML 中使用变量。详情可查here .
示例
配置文件:
<variable name="logDirectory" value="c:\temp" />
<targets>
<target xsi:type="File"
name ="processInfo"
fileName="${var:logDirectory}"
layout="${longdate} | ProcessInfo: ${message}"
/>
</targets>
代码:
LogManager.Configuration.Variables["logDirectory"] = @"c:\temp\logs";
关于c# - 如何在 NLog.Config 中使用来自不同类的变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38977847/