We use NLog in our C# service for the logging. File naming is like this:
<target name="StdLogFile"
xsi:type="File"
fileName="${LogFolder}/the-app.log"
layout="${longdate} [${uppercase:${level}}] ${message} @(${logger})"
archiveEvery="Day"
archiveNumbering="Date"
archiveDateFormat="yyyy-MM-dd"
archiveFileName="${LogFolder}/the-app_{#}.log"
maxArchiveFiles="14"
autoFlush="true" />
that is:
- Current logfile will be
the-app.log
- Archived logs will be
the-app_2015-03-10.log
We now had the problem, that due to some tests, a fiel the-app_x.log
was in the log folder. This prevented log rotation and NLog simply stopped logging to file at all.
Details:
The log folder contained:
the-app.log
from a previous daythe-app_x.log
from the same previous daythe-app_2015-..-..
etc. older archived files
NLog failed to rotate the existing the-app.log
to the archived name TRDS-Import_2015-03-10.log
and did not append to the existing the-app.log
.
Renaming "the-app_x.log
" to "X the-app_x.log
" fixed the issue, that is NLog then did rename and create a new logfile for today.
How can we:
a) Make sure log rotation always works?
b) Make the application error and quit if opening the logfile fails?