我想为例外设置这样的模式:
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="[%-5level] %date{HH:mm:ss}: %message%newlineException: %exception{message}%newlineStackTrace: %exception{stacktrace}%newline" />
</layout>
虽然我想为非例外设置这样的模式:
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="[%-5level] %date{HH:mm:ss}: %message%newline" />
</layout>
我该如何做到这一点?
这与日志级别无关,因为它可以是DEBUG
,DEBUG-EXCEPTION
,也可以是ERROR
或ERROR-EXCEPTION
答案 0 :(得分:-1)
不完全确定你在寻找什么,但我认为已经有了这样做。只要你记录这样的例外:
try
{
throw new Exception();
}
catch (Exception ex)
{
Log.Error("There was an exception!", ex)
}
以下是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)