How to tell NLog to log exceptions?

流过昼夜 提交于 2019-12-07 01:40:55

问题


Target:

<targets>
    <target name="file" xsi:type="File" layout="${longdate} ${level} ${message} ${exception}" fileName="${basedir}/log.txt" archiveAboveSize="10485760" />
</targets>

When I call Logger.Error("some message", e), where e is some exception object, it only logs the message, not the exception information. I need it to output exception message and stack trace. Any ideas what I am doing wrong?


回答1:


Try to use ${exception:innerFormat=Message,StackTrace}. Here is the documentation.




回答2:


I've found ${exception:format=tostring} to be the best format for logging full details.

NLog - How to Log Exceptions




回答3:


Yep try adding

includeSourceInfo="true"

to your target file, like;

 <target name="viewer"
            xsi:type="NLogViewer"
            includeSourceInfo="true"
            address="udp://127.0.0.1:9999" />


来源:https://stackoverflow.com/questions/9199073/how-to-tell-nlog-to-log-exceptions

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!