当我使用 NLog 记录到跟踪目标类型时,它仅在级别为Trace或时才能正常工作Debug。如果是Info, Warn, 或Error,它会在我的布局之前添加额外的信息。如果级别是Fatal,我会收到一个弹出窗口,抱怨断言失败,并且它在输出中也这么说。跟踪目标是否被窃听?
程序.cs
using System;
namespace TraceLoggingTest
{
class Program
{
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
static void Main(string[] args)
{
logger.Trace("Hello Trace");
logger.Debug("Hello Debug");
logger.Info("Hello Info");
logger.Warn("Hello Warn");
logger.Error("Hello Error");
logger.Fatal("Hello Fatal");
Console.ReadLine();
NLog.LogManager.Shutdown();
}
}
}
配置文件
<?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"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
throwExceptions="false"
internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log">
<targets>
<target name="logTrace" xsi:type="Trace" layout="${message}" />
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="logTrace" />
</rules>
</nlog>
预期输出
Hello Trace
Hello Debug
Hello Info
Hello Warn
Hello Error
Hello Fatal
实际产量
Hello Trace
Hello Debug
TraceLoggingTest.exe Information: 0 : Hello Info
TraceLoggingTest.exe Warning: 0 : Hello Warn
TraceLoggingTest.exe Error: 0 : Hello Error
---- DEBUG ASSERTION FAILED ----
---- Assert Short Message ----
Hello Fatal
---- Assert Long Message ----
相关分类