我有问题日志异常(exception),仅记录了消息。
NLog配置:
<target name="logfile"
xsi:type="File"
fileName="log.txt"
layout="${longdate} | ${machinename} | ${processid} | ${processname} | ${level} | ${logger} | |${message} | ${exception:format=tostring}" />
<logger name="*"
minlevel="Info"
writeTo="logfile" />
用法:
private static Logger _logger = LogManager.GetCurrentClassLogger();
_logger.Error("my message", new Exception("my exception"));
日志输出:
2014-04-24 18:17:29.0841 | PC_NAME | 6464 | APP_NAME.vshost | Error | AppName.ViewModel | my message |
异常(exception)是忽略。
我找到了thread,但对我来说却行不通。
最佳答案
Nlog正在使用单独的方法来记录使用<loglevel>Exception
命名模式的异常。
因此,在您的情况下,您需要使用ErrorException
方法才能正确记录异常:
private static Logger _logger = LogManager.GetCurrentClassLogger();
_logger.ErrorException("my message", new Exception("my exception"));
关于exception - Nlog错误(消息,异常)忽略异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23274497/