I have the below config for NLog (4.7.11), which creates a new log file every day or when the file is overgrown. The problem: it is not deleting the old files at all so now the log folder is full of many weeks old log files. Can you please suggest what's wrong and how to get it work?
<target name="appLogFile" type="File"
fileName="d:\my_logs\nlog_test-${date:format=yyyy-MM-dd}.log"
archiveFileName="d:\my_logs\nlog_test-{#}.log"
archiveAboveSize="104857600" archiveNumbering="DateAndSequence" archiveDateFormat="yyyy-MM-dd"
maxArchiveFiles="2" maxArchiveDays="2"
openFileCacheTimeout="30" concurrentWrites="True" keepFileOpen="True" createDirs="True"
layout="${date:format=yyy-MM-dd HH\:mm\:ss.fff K} ${message}" />
The issue looks like, you are logging into different files each day because the file names are created with the current date. On the next day, logging is done to the new file. When the replacing is not happening to the current file then the archive is not created until the maximum size is reached.
Please try the bellow configuration,
<target name="appLogFile" type="File"
fileName="d:\my_logs\nlog_test.log"
archiveFileName="d:\my_logs\archives\nlog_test-{#}.log"
archiveAboveSize="104857600" archiveNumbering="DateAndSequence" archiveDateFormat="yyyy-MM-dd"
maxArchiveFiles="2" maxArchiveDays="2"
openFileCacheTimeout="30" concurrentWrites="True" keepFileOpen="True" createDirs="True"
layout="${date:format=yyy-MM-dd HH\:mm\:ss.fff K} ${message}" />