I've configured a file target for NLog as follows:
<targets>
<target name="asyncFile" xsi:type="AsyncWrapper">
<target xsi:type="File" name="logfile" fileName="${basedir}/Logs/${shortdate}.log"
layout="${longdate} ${uppercase:${level}} ${message}" />
</target>
</targets>
How can I query the actual filesystem path (fileName
) of this File
target via NLog's API?
private string GetLogFile()
{
var fileTarget = LogManager.Configuration.AllTargets.FirstOrDefault(t => t is FileTarget) as FileTarget;
return fileTarget == null ? string.Empty : fileTarget.FileName.Render(new LogEventInfo { Level = LogLevel.Info });
}
I've just tried to get this information via the configuration api.
Sadly it looks like the configuration is evaluated by the actual target and is not resolved in the configuration.
As {basedir}
refers to the appdomain base directory you could simply read this value on your own.
var basedirPath = AppDomain.CurrentDomain.BaseDirectory;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With