NLog内部异常登录 [英] NLog Inner Exception Loggin

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

问题描述

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

I'm trying to log inner exception messages by using NLog. This is a piece of my NLog.config file:

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

对于 NLog.config 文件的Exception MessageInnerException Message行,我都收到相同的消息See the inner exception for details.

I'm getting the same message See the inner exception for detailsfor both Exception Message and InnerException Message lines of NLog.config file.

推荐答案

这对我有用:

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

属性说明:

  • ${exception:maxInnerExceptionLevel=N}-控制记录多少内部异常.为了向后兼容,默认为零.
  • ${exception:innerExceptionSeparator=TEXT}-定义用于分隔内部异常的文本.默认为新行字符串(特定于平台).
  • ${exception:innerFormat=FORMATSTRING}-定义内部异常的格式与${exception:format=FORMATSTRING}定义顶级异常的格式相同.如果未指定此参数,则顶级和内部异常将使用相同的格式.
  • ${exception:maxInnerExceptionLevel=N} - controls how many inner exceptions are logged. defaults to zero for backwards compatibility.
  • ${exception:innerExceptionSeparator=TEXT} - defines text that separates inner exceptions. Defaults to new line string (platform specific).
  • ${exception:innerFormat=FORMATSTRING} - defines the format of inner exceptions the same way that ${exception:format=FORMATSTRING} defines the format of the top-level exception. If this parameter is not specified, the same format is used for both top-level and inner exceptions.

这是官方 Nlog文档记录内部异常

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

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