1

I want to be able to set the target's filename to be a fixed name that includes the process's start time and date even if the configuration file is updated due to autoReload="true" being in the nlog intro.

I have tried the following but it recreates the log file when the log file is altered.

   <target
        name="file"
        xsi:type="File" 
        fileName="C:\Logs\${cached:cached=true:inner=${date:format=yyyyMMdd.HHmmss}}.${processid}.txt"
        layout="${time} ${level}: ${message}">
    </target>

Is there a way that I can get a time and date that is essentially fixed for the duration of the process no matter how many times the config file is updated and incorporate it into the filename?

Max Walshe
  • 11
  • 2

1 Answers1

1

You could pass a custom parameter to NLog, containing the process start date and time.

GlobalDiagnosticsContext.Set("ProcessStart", yourDateVariable);
logger.Debug("Hello world!");

And then use that as part of the filename.

${gdc:ProcessStart}
Community
  • 1
  • 1
Stijn
  • 1,970
  • 3
  • 27
  • 36