有时 nLog 不会记录所有调试信息(调试文件中缺少一些 log.Debug...),有谁知道为什么会发生这种情况以及如何避免这种情况?
这是我的 nLog 配置
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<variable name="appTitle" value="Service"/>
<targets async="true">
<target name="fallbackDebug" xsi:type="FallbackGroup" returnToFirstOnSuccess="true">
<target xsi:type="File" fileName="C:\Logs\${date:format=yyyyMMdd}_Debug.txt" layout="..."/>
<target xsi:type="File" fileName="C:\Logs\${date:format=yyyyMMdd}_Debug_bu.txt" layout="..."/>
</target>
</targets>
<rules>
<logger name="*" levels="Trace,Debug,Error,Fatal" writeTo="fallbackDebug" />
</rules>
</nlog>
在代码中我使用以下内容
private static Logger log = LogManager.GetCurrentClassLogger();
...
log.Debug("Some debug info");
谢谢!
最佳答案
您必须在最后调用 LogManager.Flush()
方法。
示例:
private static Logger log = LogManager.GetCurrentClassLogger();
...
log.Debug("Some debug info");
...
LogManager.Flush();
关于c# - nLog 丢失日志数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9806459/