NLog 配置文件按固定大小生成多文件

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <targets>
     <target name="log" xsi:type="File" fileName="${basedir}/Log/${shortdate}_log.txt" encoding="utf-8" archiveNumbering="Sequence" archiveAboveSize="104857600"/>
     <target name="debug" xsi:type="File" fileName="${basedir}/Log/${shortdate}_debug.txt" encoding="utf-8" archiveNumbering="Sequence" archiveAboveSize="104857600"/>
     <target name="trace" xsi:type="File" fileName="${basedir}/Log/${shortdate}_trace.txt" encoding="utf-8" archiveNumbering="Sequence" archiveAboveSize="104857600"/>
     <target name="exception" xsi:type="File" fileName="${basedir}/Log/${shortdate}_exception.txt" layout="${longdate} | ${level:uppercase=false} | ${message} ${onexception:${exception:format=tostring} ${newline} ${stacktrace} ${newline}" encoding="utf-8" archiveNumbering="Sequence" archiveAboveSize="104857600" />
     <target name="system" xsi:type="File" fileName="${basedir}/Log/system.txt" encoding="utf-8" archiveNumbering="Sequence" archiveAboveSize="104857600"></target>
   </targets>
   <rules>
     <logger name="system" level="Info" writeTo="system" />
     <logger name="*" level="Debug" writeTo="debug"/>
     <logger name="*" level="Trace" writeTo="trace"/>
     <logger name="*" level="Info" writeTo="log"/>
     <logger name="*" level="Error" writeTo="exception"/>
   </rules>  
</nlog>


参数:

文件编码:encoding="utf-8"

文件分割文件名附加数字顺序:archiveNumbering="Sequence"

文件分割文件名附加日期与数字顺序:archiveNumbering="DateAndSequence"

DateAndSequence中日期格式:archiveDateFormat="yyyyMMdd"

文件分割大小:单位=字节 archiveAboveSize="104857600“

posted @   94cool  阅读(633)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
历史上的今天:
2019-05-19 mysql 8创建远程访问用户以及连接mysql速度慢的解决方法
2017-05-19 Php 通过curl提交post内容为 Json的请求
2017-05-19 asp.net webapi 404/或无效控制器/或无效请求 截取处理统一输出格式
2012-05-19 Windows XP远程桌面端口更改
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示