2011-12-27 90 views
2

不同log4net的治療例外我想設置的例外是這樣一種模式:從其它日誌信息

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

我怎樣才能做到這一點?

這是從日誌級別獨立的,因爲它可能是DEBUGDEBUG-EXCEPTION,只是以及ERRORERROR-EXCEPTION

回答

-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)