NLog version: (e.g. 4.4.13)
Platform: .NET Core 3
Current NLog config (xml or C#, if relevant)
<?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">
<targets>
<target xsi:type="File" name="f" fileName="file.log" autoFlush="true" keepFileOpen="true" concurrentWrites="true" archiveFileName="file-{#}.log" archiveNumbering="Date" archiveDateFormat="yyyy-MM-ddThh-mm-ss" maxArchiveFiles="1" archiveEvery="Day">
<layout xsi:type="JsonLayout">
<attribute name="time" layout="${date:universalTime=false:format=yyyy-MM-ddTHH\:mm\:ss.fffZ}"/>
</layout>
</target>
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="f" />
</rules>
</nlog>
Current result: no archive files are kept
Expected result: one archive file is kept
Worked well in v4.0.0.0
This is very similar to #2775 which is closed as a dup of #1479, but the latter is still open and it is not clear whether its fix will actually address the issue.
Please note, this blocks our project from migration to .Net Core; will likely block others as well.
Hi! Thanks for opening your first issue here! Please make sure to follow the issue template - so we could help you better!
Attaching internal log that corresponds to the following manual test:
Have you tried dusing the new option MaxArchiveDays=1 on FileTarget introduced with NLog 4.7:
<?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">
<targets>
<target xsi:type="File" name="f" fileName="file.log" autoFlush="true" keepFileOpen="true" concurrentWrites="true" archiveFileName="file-{#}.log" archiveNumbering="Date" archiveDateFormat="yyyy-MM-ddThh-mm-ss" maxArchiveDays="1" archiveEvery="Day">
<layout xsi:type="JsonLayout">
<attribute name="time" layout="${date:universalTime=false:format=yyyy-MM-ddTHH\:mm\:ss.fffZ}"/>
</layout>
</target>
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="f" />
</rules>
</nlog>
Works well, thank you! I think this issue can be closed.
Guys, I spent about 1 hour to figure out why maxArchiveFiles="1" won't working.
It's not normal, that:
with maxArchiveFiles = 1, I will get the current log file only (i.e. NO archive files) :confused:
and with maxArchiveFiles = 2, I will get 2 archive files. - correct.
This is really a bug, and if you interpret it like a _feature_, there must be a big warning about it in the docs, and described workaround with maxArchiveDays...
Ups:

So, with archiveNumbering = "Rolling" workaround above will not work at all :(
Any advice, how to achieve this:
maxArchiveFiles = "1"
archiveFileName = "${basedir}/log/our/WDlog.{#}.txt"
archiveNumbering = "Rolling"
archiveEvery="Month"
1 current log and 1 archive log, updated every month.
Thanks.
cc @304NotModified @snakefoot
@kirsan31 You are very welcome to create a more logical implementation of maxArchiveFiles for NLog 5.0 (dev-branch) with a pull-request.
Maybe read the comments for #2775 and #1479 before doing the implementation.
Most helpful comment
Works well, thank you! I think this issue can be closed.