Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

NLog generates too many archives

I’m using NLog configured this way:

var logfile = new NLog.Targets.FileTarget("logfile")
{
    FileName = Path.Combine(_logDirectory, "myApp.log"),
    Layout = "${date} [${level}] ${message} ${exception}${newline}",
    ArchiveFileName = Path.Combine(_logDirectory, "myApp.{#}.log"),
    ArchiveAboveSize = 100 * 1024, MaxArchiveFiles = 9
};

On the file target syntax documentation it says that the number of {#} characters in the ArchiveFileName property are used to determine the number of digits. As you can see I’ve only put one hash character but the result is that I’m getting an archiving that goes way beyond myApp.9.log, it can easily reach past .100.
What am I doing wrong?

Thanks for your help

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I’m guessing that you want rolling filenames. Try adding ArchiveNumbering = NLog.Targets.ArchiveNumberingMode.Rolling.

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading