我正在尝试使用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="\Logs\errors-${shortdate}.log"
concurrentWrites="true" />
</targets>
对于 NLog.config 文件的
See the inner exception for details
和Exception Message
行,我都得到了相同的消息InnerException Message
。
最佳答案
这为我工作:
<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)都使用相同的格式。 这是用于记录内部异常的官方Nlog Documentation
关于logging - NLog内部异常记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44287491/