码迷,mamicode.com
首页 > 其他好文 > 详细

NLog rolling file

时间:2020-07-03 15:55:03      阅读:68      评论:0      收藏:0      [点我收藏+]

标签:github   date   deb   mic   recently   ext   href   line   bin   

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" />

 

NLog rolling file

标签:github   date   deb   mic   recently   ext   href   line   bin   

原文地址:https://www.cnblogs.com/chucklu/p/13230411.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!