Reputation: 671
In some of my programs I have a 30 day rotation as expected with multiple entries from several months, but only 30 log files. In other programs, I have only one day's worth of log files, but still only 30 log files total. What I want to have is just the log file entries from the last 30 days with 30 log files. I guess I don't know what I am missing.
Yesterday one of my log files was overwritten when the program started back up so I lost the data that would tell me what happened. Then my second question is, does archiving just remove the files that don't fit the pattern or does it actually take the log files and put them somewhere? What really is archiving? Here is my nlog.config:
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!--
See https://github.com/nlog/nlog/wiki/Configuration-file
for information on customizing logging rules and outputs.
-->
<variable name="LogDir" value="${specialfolder:folder=MyDocuments}/MyApp/Log"/>
<variable name="LogDay" value="${date:format=dd}"/>
<targets async="true">
<!-- add your targets here -->
<target name="LogTarget1"
xsi:type="File"
fileName="${LogDay}.log"
encoding="utf-8"
maxArchiveFiles="30"
archiveNumbering="Sequence"
archiveAboveSize="52428800"
archiveFileName="${LogDay}.{#######}.log"
layout="${date:format=MM/dd/yyyy HH\:mm\:ss}|${level:uppercase=true}|${message}" />
</targets>
<rules>
<!-- add your logging rules here -->
<logger name="*" minlevel="Trace" writeTo="LogTarget1" />
</rules>
</nlog>
Upvotes: 5
Views: 11374
Reputation: 36700
This is a shortcoming of NLog which isn't documented well.
When files should be deleted (e.g. max archives files) then the log files and archive files can't be in the same folder.
So one fix for this config would be to change the archifeFilePath to
archiveFileName="archive/${LogDay}.{#######}.log"
See also this issue on GitHub
Upvotes: 4