I want to use <appsetting>
in NLog (the NLog.Extended NuGet package to be specific) to do something like this:
<variable name="logDir" value="${appsetting:name=RemoteLogDir:default=.\Log}" />
Where I set up RemoteLogDir
when I publish my app, but fallback to a relative directory for local development. I've been able to get an absolute path to work, but that doesn't seem collaborator-friendly.
How can I get a relative path to work? Or do I need to submit a feature request?
Notes:
- I'm using NLog 4.4.12 and NLog.Extended 4.0.0.1.
- I'm using .NET 4.6.1 on Windows (10).
- I've cross posted to the NLog repository.
- The NLog.config is this:
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true" throwExceptions="false">
<variable xsi:type="NLogVariable" name="appLogName" value="MyApp"/>
<variable xsi:type="NLogVariable" name="logDir" value="${appsetting:name=RemoteLogDir:default=\.\\Log}" />
<variable xsi:type="NLogVariable" name="layout" value="${level:uppercase=true} | ${date:format=MM/dd/yyyy HH\:mm\:ss} | ${machinename} | ${windows-identity:domain=true} | ${callsite} ${newline} ${message}${onexception:${newline}[EXCEPTION]${newline}${exception:format=tostring}}" />
<variable xsi:type="NLogVariable" name="logFileName" value="${var:logDir}/${var:appLogName}_${date:format=yyyy-MM-dd}.txt" />
<variable xsi:type="NLogVariable" name="archiveLogFileName" value="${var:logDir}/Archive/${var:appLogName}_Archived_{#}.txt" />
<targets>
<target name="singleFile" xsi:type="File"
layout="${var:layout}"
fileName="${var:logFileName}"
concurrentWrites="true"
keepFileOpen="true"
archiveFileName="${var:archiveLogFileName}"
archiveEvery="Day"
archiveNumbering="Date"
archiveDateFormat="yyyy-MM-dd_HH"
maxArchiveFiles="30" />
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="singleFile" />
</rules>
</nlog>