NLog内部异常记录 [英] NLog Inner Exception Logging

查看:0
本文介绍了NLog内部异常记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用NLog记录内部异常消息。这是我的NLog.config文件的一部分:

    <target name="errors" xsi:type="File" layout="${longdate}${newline}
        - Exception Message: ${exception:format=Message}${newline}
        - InnerException Message: ${exception:innerExceptionSeparator=TEXT}${newline}"
        fileName="Logserrors-${shortdate}.log"
       concurrentWrites="true" />
    </targets>

文件的Exception MessageInnerException Message行的See the inner exception for details消息相同。

推荐答案

这对我有效:

  <target name="errors" xsi:type="File" layout="
            ${message}
            ${onexception:EXCEPTION OCCURRED:
            ${exception:format=type,message,method:maxInnerExceptionLevel=5:innerFormat=shortType,message,method}}"
            fileName="Logserrors-${shortdate}.log"
            concurrentWrites="true"
            />
  </targets>

属性说明:

  • ${exception:maxInnerExceptionLevel=N}-控制记录多少内部异常。为向后兼容,默认设置为零。
  • ${exception:innerExceptionSeparator=TEXT}-定义分隔内部异常的文本。默认为新行字符串(特定于平台)。
  • ${exception:innerFormat=FORMATSTRING}-定义内部异常的格式,与${exception:format=FORMATSTRING}定义顶级异常的格式相同。如果未指定此参数,则顶级异常和内部异常使用相同的格式。

这是记录内部异常的官方Nlog Documentation

这篇关于NLog内部异常记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆