NLog中maxArchiveDays与DateAndSequence配置的兼容性咨询
Can
maxArchiveDays Work with archiveNumbering="DateAndSequence" in NLog? Great question! Let's break this down clearly since the documentation calls out limitations for pure Sequence mode but doesn't explicitly cover DateAndSequence.
The short answer: Yes, your configuration is fully valid and functional. Here's why:
archiveNumbering="DateAndSequence"combines date-based naming with sequence numbers (e.g.,app_20240520_001.log,app_20240520_002.log). Unlike pureSequencemode (which only uses incrementing numbers likeapp_001.log), this mode embeds a clear date stamp in archive filenames.maxArchiveDaysrelies on being able to determine the age of archive files. WithDateAndSequence, NLog can parse the date from the filename to calculate if a file is older than your specified 30 days. It will automatically clean up any archives where the embedded date is more than 30 days in the past, while keeping all sequence files from the last 30 days intact.
To confirm, here's a simplified working config snippet that mirrors your setup:
<target xsi:type="File" name="appLog" fileName="./logs/app.log" archiveFileName="./logs/app_{#}.log" archiveNumbering="DateAndSequence" archiveDateFormat="yyyyMMdd" maxArchiveDays="30" archiveEvery="Day" />
The key distinction from pure Sequence mode is that DateAndSequence provides the date context NLog needs to apply the maxArchiveDays cleanup logic. You won't run into the same limitations here, as the date in the filename gives NLog a concrete reference point for determining file age.
内容的提问来源于stack exchange,提问作者Semperfi89
相关产品推荐
相关产品推荐

