nlog - NLog - 文件轮换 - 序列问题
问题描述
我每天都使用 Nlog 来记录日志和旋转文件。日志文件由另一个系统进一步读取和处理以移动到 Splunk。
在这里,我希望找出 nlog 需要哪些步骤来旋转文件,因为它无法与其他系统集成。它适用于其他日志框架,如 log4net/logback。如果是这种情况,我可能需要切换到其他框架。
理想的步骤应该是 - 方法 1
1. Open file - abc.txt
2. add log line 1, log line 2.. log line n.
3. 12.00 AM - file rotation - Rename file abc.txt => 2020-05-13 abc.txt
4. create new file - abc.txt 5. add log line a1, log line a2.. log line an.
另一种方法可能是 - 方法 2
1. open file - abc.txt
2. add log line 1, log line 2.. log line n.
3. 12.00 AM - file rotation - create new file 2020-05-13 abc.txt
4. move contents from abc.txt to new file 2020-05-13 abc.txt
5. Update file offset/pointer to move to new location i.e. start of the file (as contents are removed from this file)
6. add log line a1, log line a2.. log line an - at the begining location (offset/file pointer)
任何人都可以确认 Nlog 究竟执行了哪种方法或步骤序列来进行文件轮换。
[更新] 下面是我的配置的样子-
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<variable name="logDir" value="C:\logs">
<targets>
<target name="logFile" xsi:type="File" fileName="${logDir}\API_${machinename}.json"
archiveFileName="${logDir}\{#}_API_${machinename}.json" archiveNumbering="Date"
archiveDateFormat="yyyy-MM-dd" archiveEvery="Day">
<layout xsi:type="JsonLayout" includeAllProperties="true">
<attribute name="time" layout="${date:format=yyyy-MM-ddTHH\:mm\:ss.fffzzz}"/>
<attribute name="level" layout="${level:upperCase=true}"/>
<attribute name="message" layout="${message}"/>
<attribute name="exception" layout="${exception:format=@}"/>
</layout>
</target>
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="logFile" />
</rules>
</nlog>
解决方案
推荐阅读
- javascript - 映射一个 json 文件以获取一个数组,其中只有我需要的值
- postgresql - 带有 EFS 卷的 AWS Fargate 上的 Postgresql 导致“管道损坏”错误
- c - 算法的时间复杂度 - 大 O
- python - 如何使用Python获取行为空白的Excel的列名
- ssl - SSL 对等方无法协商一组可接受的安全参数
- vba - VBA - 在 Microsoft Word 2016 中禁用限制样式更改
- java - 添加两个 JPanel 时的问题
- php - 文件获取内容谷歌地理编码不起作用
- ios - React Native IOS 崩溃:com.facebook.react.JavaScript SIGTRAP 0x00000001a065be50
- php - CI 4 -