I\'ve configured a file target for NLog as follows:
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;
You could use nLog's api inside of code instead of an xml configuration file. Then, in your application, you assign the log's file path to a variable, and use that variable as the target's filename. You can access that variable, OR change it anytime you like (my snippet, here, is defined inside of a class).
Private MainNlogConfig As New LoggingConfiguration()
Dim localrule As New LoggingRule(*, LogLevel.Info, locallogtarget)
MainNlogConfig..AddTarget("file", locallogtarget)
With locallogtarget
.Layout = "${longdate} ${logger} ${message}"
.FileName = appdir & appName & ".log" '----->LOOK HERE!
End With
LogManager.Configuration = MainNlogConfig