nlog and MaxArchiveFiles

I love the concept of a central logging file path with v14, but so far am not loving having to remember to clean them out before the directory fills up.  We use LogRhythm and would ideally like it to archive our files, letting nlog clean up after itself every 2 days or so.  With the MaxArchiveFiles feature in the nlog.config this should be possible, but.... (isn't there always a but?)

...nlog seems to only write to a path (either central or local) if the short date is in the log name.  And when that happens, the MaxArchiveFiles feature is practically useless.  For example, if we archive hourly and set MaxArchiveFiles to 48 (2 days), one would assume that all logs older than 2 days would be deleted.  But instead, nlog seems to look only at the stream (the log name before the .00000, .00001),etc. to determine if the volume of logs has been reached and needs to be tidied up.  A daily log stream will never have more than 24 log archives, well below our MaxArchiveFiles threshold.  If I remove the short date from the log name, then nlog doesn't write anything at all.  I have tested this today by removing the short date from the central file path in nlog.config and watched as the logs wrote to the local directory instead. I add the short date back to the central file path and they start writing there again. (When you think about it, why do I need the short date in the log name if the log itself has a date created/modified property?)  

How do you use the central logging of nlog in v14?  Or if you're not there yet, how do you automate log file clean up?  

Thanks!

Nancy

Parents
  • We let Nlog clean out the logs for us, but a twist we add is to create a separate dir for each machine, i.e. our client logs are written to

    fileName="\\[our server name]\logs\Tessitura\TessituraClient\${machinename}\${dateformat}.log"

    With the "\" instead of a "-" between $machinename and $dateformat, we get separate dirs per machine, containing dated/numbered logs, which get housekept via the maxArchiveFiles setting.

Reply
  • We let Nlog clean out the logs for us, but a twist we add is to create a separate dir for each machine, i.e. our client logs are written to

    fileName="\\[our server name]\logs\Tessitura\TessituraClient\${machinename}\${dateformat}.log"

    With the "\" instead of a "-" between $machinename and $dateformat, we get separate dirs per machine, containing dated/numbered logs, which get housekept via the maxArchiveFiles setting.

Children
  • I hadn't noticed before, but you're right, Nancy, the MaxArchiveFiles setting doesn't quite act the way I'd expected, but I hadn't really noticed before due to dividing up client files as described above.

    No matter, I'll clean up the logs with the forfiles command via a scheduled bat file, as I do a bunch of others, e.g.

    :: Tessitura logs older than 30 days
    NET USE V: \\[our server]\logs\tessitura
    forfiles -p V: -s -m *.log -d -30 -c "cmd /C DEL @File"