NLog 传递参数

   用NLog记文件日志,一般都用{$basedir}变量,把日志记在运行的目录或者它的子目录下,遇到要写在其他目录的下,看了下Nlog找到用环境变量传参数。

.net 里写 

 Environment.SetEnvironmentVariable("maindir",@”c:log");
         

Nlog.config 配置

   <targets>
     
    <target name="logfile" type="File" layout="datetime:${date}, message:${message} ${newline} "  fileName="${environment:variable=maindir}/log/${shortdate}.txt" />

  </targets>

原文地址:https://www.cnblogs.com/peteryu007/p/4213279.html