NLog rolling file
Archive old log files
NLog 4.5 makes it easy to setup archive logic to move/cleanup old files with dynamic fileName-Layout. You just need to configure maxArchiveFiles
and it will automatically perform cleanup.
<?xml version="1.0" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="file" xsi:type="File"
layout="${longdate} ${logger} ${message}${exception:format=ToString}"
fileName="${basedir}/logs/AppLog.${shortdate}.txt"
maxArchiveFiles="4"
archiveAboveSize="10240" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="file" />
</rules>
</nlog>
NLog 4.7 (and newer) adds support for the option MaxArchiveDays
. It works like MaxArchiveFiles
but instead inspect the timestamp of the files in the archive. They can be combined. Ex. maxArchiveDays="30" maxArchiveFiles="90"
(Deletes files older than 30 days or if more than 90 files in archive).
If using NLog older than ver. 4.5 (or have very special needs), then also see FileTarget-Archive-Examples
用archiveAboveSize进行处理的话,流程是
1.默认error.log
2.第一次rolling,把error.log重命名为error.1.log,新建error.log
3.第二次rolling,把error.log重命名为error2.log,新建error.log
数字越大的archive,是most recently
FileTarget Archive Examples
NLog ver. 4.5 makes it very easy to perform archive of old files.
But there are many archival options, which allows one to configure the archive logic even further. This can be needed if using NLog older than ver. 4.5.
Most useful NLog configurations [closed]
Tell NLog to watch and automatically reload the configuration if it changes:
<nlog autoReload="true" />
maxArchiveFiles - Maximum number of archive files that should be kept. If maxArchiveFiles is less or equal to 0, old files aren't deleted Integer Default: 0
作者:Chuck Lu GitHub |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2019-07-03 Javascript 面向对象编程(一):封装
2019-07-03 Javascript继承机制的设计思想
2019-07-03 __proto__ VS. prototype in JavaScript
2019-07-03 ClientScriptManager.RegisterClientScriptBlock Method 无效
2018-07-03 同一个站点下,兼容不同版本的JQuery Can I use multiple versions of jQuery on the same page?
2018-07-03 DataTables
2017-07-03 ControlDesigner