0

I have been trying to get my logging working so that I can maintain a 2 week archive of daily logs.

From looking at the official documentation and this question, I have added the following to my NLog.config file target

<target name="file"
        xsi:type="File"
        fileName="${basedir}/../logs/${shortdate}.log"
        archiveFileName="${basedir}/../logs/archive/archive.${shortdate}.{#}.txt"
        archiveEvery="Day"
        archiveNumbering="Rolling"
        maxArchiveFiles="14" />

My understanding is that this should on detection of a new day, create the archive.${shortdate}.{#}.txt file in the archive folder.

What I am actually seeing is that a new log file is generated for each day which is expected, but the archiving is never occurring.

Am I configuring this wrongly, or is there something different you need to do to get this to work with NLog 2.0.1

Note that I am testing this my just manually changing my computer's date settings, although I have had it running over night once and still nothing was archived.

Edit: I have been able to get some archiving working if I change the target to archive based on file size like so:

<target name="file"
        xsi:type="File"
        fileName="${basedir}/../logs/${shortdate}.log"
        archiveFileName="${basedir}/../logs/archive/archive.${shortdate}.{#}.txt"
        archiveAboveSize="51200"
        archiveNumbering="Rolling"
        maxArchiveFiles="14" />

So just seems to be something wrong in the day archiving

Community
  • 1
  • 1
Thewads
  • 4,953
  • 11
  • 55
  • 71
  • 1
    There a lot of bugs regarding file archiving fixed. 4.0 is out for a few weeks and 4.1 RC is also on nuget. NLog 2.0 is from 2011. You should check this after an upgrade. – Julian Aug 26 '15 at 21:48
  • 1
    I had the same experience that @Julian described. 2.* archiving had issues. I upgraded to 4.2.3 today and it's all working as intended. – Mike L Dec 23 '15 at 21:23

1 Answers1

1

I stumbled across this while I was trying to find a solution to a similar problem. I know it's a bit late for an answer but maybe it will help someone else.

I believe that the problem is that you have archiving setup to be daily, but you also have named the log using the date.

This means that everyday a new log is created, so the current log is never older than one day, meaning that there is never anything to archive.

If you change the log name it should work, or you could change the archiving interval to something shorter e.g. Hour

Reznoir
  • 909
  • 1
  • 11
  • 27