FreeG
FreeG

Reputation: 95

nlog old archive files aren't deleted: archiveNumbering=Date,archiveOldFileOnStartup,maxArchiveFiles

NLog Version 4.3.6

This target creates a logfile in the log directory in the following format Trace_2016-08-03.log the logfile is moved on startup to the archive directory with a name like Trace_2016-08-03_11h33m32s_743ms.log however old archive files aren't deleted (maxArchiveFiles=2). Can anybody help me on this. I can't figure out what i'm doing wrong.

<target name="AsyncTrace" xsi:type="AsyncWrapper">
  <target name="TraceFile" xsi:type="File"
    layout="${time} ${level} ${message} ${exception:format=tostring}"
    fileName="${localLogHome}/Trace_${shortDate}.log" 
    archiveFileName="${localLogHome}/Archive/Trace_{#}.log"
    archiveNumbering="Date"
    archiveDateFormat="yyyy-MM-dd_HH\hmm\mss\s_fff\m\s"
    archiveOldFileOnStartup="true"
    maxArchiveFiles="2"
      />
</target>

Thank you for any answers!

Upvotes: 1

Views: 6172

Answers (1)

FreeG
FreeG

Reputation: 95

There are 2 problems with this configuration.

  1. The fileName (of the normal logFile) contains a Date. see https://github.com/NLog/NLog/issues/354

  2. The archive fails to recognize existing archive files when archiveDateFormat contains escapechars like in my example so yyyy-MM-dd_HH\hmm\mss\s_fff\m\s was transformed to yyyy-MM-dd_HH.mm.ss

    <target name="AsyncTrace" xsi:type="AsyncWrapper">
        <target name="TraceFile" xsi:type="File"
            layout="${time} ${level} ${message} ${exception:format=tostring}"
            fileName="${localLogHome}/Trace.log" 
            archiveFileName="${localLogHome}/Archive/Trace_{#}.log"
            archiveNumbering="Date"
            archiveDateFormat="yyyy-MM-dd_HH.mm.ss"
            archiveOldFileOnStartup="true"
            maxArchiveFiles="1"
      />
    

Upvotes: 1

Related Questions