0

Is there a way to create a log rotation with NLOG that records a log for each day for seven days and then archives them after the seven days?

this is my current target with this i :

<target xsi:type="File"
            name="error"
            layout="${longdate} ${uppercase:${level}}: - ${message}"
            fileName="${basedir}/logs/Error.log"
            archiveFileName="${basedir}/logs/archive/Error{#}.zip"
            archiveNumbering="Rolling"
            enableArchiveFileCompression="true"
            archiveEvery="Sunday"
            archiveAboveSize="10000000"
            maxArchiveDays ="28"
            archiveDateFormat="yyyy-MM-dd"
            concurrentWrites="false"/>
PsyOrc
  • 47
  • 8

1 Answers1

0

NLog likes to have single static file, but maybe this is possible:

<target xsi:type="File"
            name="error"
            layout="${longdate} ${uppercase:${level}}: - ${message}"
            fileName="${basedir}/logs/Error.${date:format=ddd}.log"
            archiveFileName="${basedir}/logs/archive/Error.{#}.zip"
            archiveDateFormat="yyyy-MM-dd"
            archiveNumbering="DateAndSequence"
            archiveEvery="Day"
            enableArchiveFileCompression="true"
            archiveAboveSize="10000000"
            maxArchiveDays ="28"
            concurrentWrites="false"/>

Then ${basedir}/logs/-folder will grow to have 7 files:

  • Error.Mon.log
  • Error.Tue.log
  • Error.Wed.log
  • Error.Thu.log
  • Error.Fri.log
  • Error.Sat.log
  • Error.Sun.log

And when "rolling" to next file that already exists (ex. Error.Mon.log), then the old file will be moved to ${basedir}/logs/archive/-folder and renamed to Error.yyyy-MM-dd.log (Using timestamp of when the old file was created)

See also: https://github.com/NLog/NLog/wiki/FileTarget-Archive-Examples

Rolf Kristensen
  • 17,785
  • 1
  • 51
  • 70