NLog rotate and cleanup logfiles

NLog 4.5 (and newer) improves the support for dynamic fileName-Layout and archive-logic.

You can do this:

    <target name="file" xsi:type="File"
        fileName="${basedir}/logs/Log.${level}.${shortdate}.txt"
        archiveAboveSize="5242880"
        maxArchiveFiles="3" />

NLog 4.7 also introduces the setting maxArchiveDays for the FileTarget.

See also https://github.com/NLog/NLog/wiki/File-target#archive-old-log-files


It looks like the problem is the shortdate in your filename definition. See my answer at this question: Delete log files after x days

You have to define the filename without the date part

fileName="${basedir}/logs/Log.info.txt