问题
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