【发布时间】:2020-12-08 18:13:33
【问题描述】:
每天在我的 Windows 服务中滚动日志文件时,Nlog 不会写入标头。如果日志文件不存在,则写入标题,如果 archiveEvery="Minute" 则将标题写入新日志文件。这是 nlog 配置文件:
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
internalLogLevel="trace"
internalLogFile="C:\Log\InnerLog.txt"
throwExceptions="true">
<variable name="AppName" value="Test Service" />
<targets>
<target
name="logfile"
xsi:type="File"
fileName="C:\Log\smgresp${date:format=MM-dd-yyyy}.log"
layout="${longdate} ${level:uppercase=true} ${message}"
archiveEvery="Day"
maxArchiveFiles="30"
header="${AppName} version ${assembly-version}"
/>
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="logfile" />
</rules>
</nlog>
这是一个错误吗?我正在通过在我的代码中检查一天的第一个日志条目并将标题等效为 Info 条目来解决它。
【问题讨论】:
-
切记不要使用
throwExceptions="true",除非万不得已,在排除 NLog.config 无法正确加载的原因时。它用于单元测试,会在生产环境中导致不需要的行为。 -
谢谢 - 我已经从配置文件中删除了。
标签: nlog