In this case, it is easier to use variables. ( ${var:...} )
In this example:
<variable name="basedir" value="${basedir}" /> <targets> <target name="asyncFileLog" xsi:type="AsyncWrapper"> <target name="logfileTrace" xsi:type="File" fileName="${var:basedir}/logs/${shortdate}Trace.log" layout="${longdate} ${message}" lineEnding="Default"/> </target> ...
Changing a variable in C #
// create or edit LogManager.Configuration.Variables["basedir"] = "d:/mybasedir";
No need for LogManager.ReconfigExistingLoggers(); or iterate over all the targets!
See also the documentation ${var}
Update : in this case you are reading .config files, this can only be done with the NLog configuration (no need for C #!)
Install NLog.Extended and use ${appsetting:name=..}
eg.
fileName="${var:basedir}/logs/${appsetting:name=RutaLog}Trace.log"
See also the documentation ${appsetting}
source share