Get the actual filename for target

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Get the actual filename for target

you need to write a custom target

follow the instructions under

then modify it to be an interceptor only and add the ActualLogfile property

public sealed class InterceptTarget : FileTarget
    public string ActualLogfile { get; set; }

    protected override void Write(LogEventInfo logEvent)
        ActualLogfile = this.FileName.Render(logEvent);
        string logMessage = this.Layout.Render(logEvent);
NLog.config should be something like this:

    <target name="i"
            fileName="${basedir}\logs\${shortdate}.log" />
    <logger name="*" minLevel="Trace" writeTo="i"/>
remark: be shure to generate a very early log message (at pgm start), before ActualLogFile is empty.