仅当抛出异常时才将堆栈跟踪写入日志文件
我只想在出现异常时才写入堆栈跟踪,目前我是这样做的,
layout="${longdate}|${level}|${message} ${exception:format=tostring} | ${stacktrace}"
所以我总是将它放在日志文件中。
编辑:
我对所有日志记录使用此布局,因此当我没有任何异常时,我也会得到堆栈跟踪。但只有当我有一些异常时,我才需要它,
当我有异常时,我有以下输出,这就是我需要的
2011-07-01 22:59:02.3782|Debug|fffffffffffffffffffffffffffff System.Exception: Exception of type 'System.Exception' was thrown. | AppDomain.ExecuteAssembly => AppDomain._nExecuteAssembly => Program.Main
但无一例外:
2011-07-01 22:57:26.7117|Trace|fffffffffffffffffffffffffffff | AppDomain.ExecuteAssembly => AppDomain._nExecuteAssembly => Program.Main
但我只想
2011-07-01 22:57:26.7117|Trace|fffffffffffffffffffffffffffff
需要如何做到这一点的想法......
I want to write the stack trace only when I have exceptions, currently I do it like this
layout="${longdate}|${level}|${message} ${exception:format=tostring} | ${stacktrace}"
So I always get it in my log file.
EDIT:
I use this layout for all my logging, so when I dont have any exceptions I also get the stack trace.But I need it only when i have some exception
when I have an exception I have following output, and it what I need
2011-07-01 22:59:02.3782|Debug|fffffffffffffffffffffffffffff System.Exception: Exception of type 'System.Exception' was thrown. | AppDomain.ExecuteAssembly => AppDomain._nExecuteAssembly => Program.Main
But without exception :
2011-07-01 22:57:26.7117|Trace|fffffffffffffffffffffffffffff | AppDomain.ExecuteAssembly => AppDomain._nExecuteAssembly => Program.Main
But I want only
2011-07-01 22:57:26.7117|Trace|fffffffffffffffffffffffffffff
Need ideas how to do so...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用以下布局:
you can use the following layout:
是的,在 NLog 中,您可以使用不同级别的 Warn、Error Info 等。您还可以使用 ErrorException、WarnException、InfoException 记录异常。 IE
如果您想显示异常,请使用以下命令。
更新:
删除 {stacktrace}
更新:
您将从异常中获取堆栈跟踪。
Yes, in NLog you can use different levels Warn, Error Info etc. You can also log the exceptions with ErrorException, WarnException, InfoException. IE
If you want to show the exception then use the following.
Update :
Remove {stacktrace}
Update :
You will get the stacktrace from the exception.