我的NLog配置如下
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="file" xsi:type="File" fileName="${basedir}/log${shortdate}.txt" archiveAboveSize="500000" archiveEvery="Day" archiveNumbering="Rolling" maxArchiveFiles="10" layout="${date:format=s}|${level}|${callsite}|${identity}|${message}|${exception:format=stacktrace}"/>
<!--<target name="console" xsi:type="Console" />-->
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="file" />
<!--<logger name="*" minlevel="Debug" writeTo="console" />-->
</rules>
</nlog>
但是当异常发生时堆栈跟踪没有被记录。 NLog 有错误吗?
我已经围绕 Nlog 创建了一个包装器,我正在记录如下
public void Error(string message, Exception ex)
{
logger.Error(message, ex);
}
我在日志中收到了消息,但在堆栈跟踪中却没有。
提前致谢
最佳答案
在你的布局中试试这个:
${exception:format=ToString}
关于c# - Nlog 未记录堆栈跟踪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12498812/