[英]Log4net treat exceptions different from other log messages
I want to set a pattern like this for exceptions: 我想为异常设置这样的模式:
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="[%-5level] %date{HH:mm:ss}: %message%newlineException: %exception{message}%newlineStackTrace: %exception{stacktrace}%newline" />
</layout>
Whilst I want to set a pattern like this for non-exceptions: 我想为非例外设置这样的模式:
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="[%-5level] %date{HH:mm:ss}: %message%newline" />
</layout>
How can I accomplish this? 我该怎么做?
This is independant from log level, since it could be DEBUG
, DEBUG-EXCEPTION
, just as well as ERROR
or ERROR-EXCEPTION
这与日志级别无关,因为它可能是
DEBUG
, DEBUG-EXCEPTION
以及ERROR
或ERROR-EXCEPTION
Not entirely sure what you're looking for but I think it kind of does this already. 不能完全确定您要查找的内容,但我认为已经做到了。 As long as you log your exceptions like this:
只要您记录这样的异常:
try
{
throw new Exception();
}
catch (Exception ex)
{
Log.Error("There was an exception!", ex)
}
Here's an example for PowerGUI VSX: 这是PowerGUI VSX的示例:
2012-01-25 23:04:21,539 [1] FATAL PowerGui.AddOn.PowerGuiComposer [(null)] - There was an unhandled exception! OMG WTF!
System.Windows.Markup.XamlParseException: The invocation of the constructor on type 'QuickConsole.MainWindow' that matches the specified binding constraints threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Engine, Version=3.1.0.2058, Culture=neutral, PublicKeyToken=a69c32b63191909f' or one of its dependencies. The system cannot find the file specified.
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.