logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nicko Cadell" <ni...@neoworks.com>
Subject RE: Customize the exception output
Date Sun, 09 Jul 2006 01:04:43 GMT
The PatternLayout uses the ObjectRenderer framework to convert the
Exception object into a string. The DefaultRenderer will just call the
ToString method on the Exception object. The ToString method can be
overridden by Exception subclasses.

If you want to use a custom rendering for Exception objects then you can
add your own custom exception renderer.
http://logging.apache.org/log4net/release/manual/configuration.html#rend
erers

The configuration can be specified in the log4net config file as:

<renderer renderingClass="MyExceptionRenderer"
renderedClass="System.Exception" /> 

And you need to build a class to do the rendering which implements the
log4net.ObjectRenderer.IObjectRenderer interface.

Cheers,
Nicko

> -----Original Message-----
> From: Sean Carlin [mailto:seancarlin@gmail.com] 
> Sent: 21 June 2006 16:28
> To: log4net-user@logging.apache.org
> Subject: Customize the exception output
> 
> Hi,
>  
> I've had a request from the developers at my company to 
> modify the way in which log4net outputs exceptions to the 
> log.  This would need to take effect in my EventLogAppender 
> and AdoNetAppender.  Will I need to create my own custom 
> class similar to ExceptionLayout or a custom class similar to 
> ExceptionPatternConverter?  How can I specify this change to 
> the EventLogAppender?
> 
> The request is to format the exception more like the way the 
> .NET Enterprise Library did in .NET 1.1.:
>  
> 1) Exception Information
> 
> *********************************************
> 
> Exception Type: X.WebApps.NewsRoom.WebControls.NewsSystemException
> 
> Message: Could not retrieve a list of articles from the category
> 
> Data: System.Collections.ListDictionaryInternal
> 
> TargetSite: NULL
> 
> HelpLink: NULL
> 
> Source: NULL
> 
> 2) Exception Information
> 
> *********************************************
> 
> Exception Type: System.Exception
> 
> Message: An error occurred while processing the required SQL 
> script: 
> D:\WebSites\X\WebAppsFolders\WebAppsCommonFiles\\scripts\core.config
> 
> Data: System.Collections.ListDictionaryInternal
> 
> TargetSite: Void ExecuteScripts(System.String, 
> System.String[], Boolean, Boolean)
> 
> HelpLink: NULL
> 
> Source: X.WebApps.CoreLibrary.X.X
> 
> StackTrace Information
> 
> *********************************************
> 
> at X.WebApps.CoreSystem.ExecuteScripts(String path, String[] 
> scripts, Boolean trapExceptions, Boolean sendAppPath)
> 
> at X.WebApps.CoreSystem.SystemInit()
> 
> at X.WebApps.CoreSystem..ctor(String application)
> 
> at 
> X.WebApps.NewsRoom.WebControls.NewsArticleDisplayer.GetNewsArt
> icleAndCategory(Category& newsCategory, Article& newsArticle)
> 
>  
> Here is a sample of what is being output by the default format:
>  
> System.Exception: Testing application error handling from the 
> DevCenter/ApplicationErrorTest.aspx form. ---> 
> System.ArrayTypeMismatchException: Oh my gosh some sort of 
> array mismatch occurred in this fake class! Error! Error!
> at RemoteNet.Zapenza.Utility.TestClass..ctor() in 
> C:\Solutions\CIProjects\RemoteNet\Zapenza\Working\Source\Remot
> eNet.Zapenza.Utility\TestClass.cs:line 11 at 
> DevCenter_ApplicationErrorTest.lnkApplicationError_Click(Objec
> t sender, EventArgs e) in 
> c:\Solutions\CIProjects\RemoteNet\Zapenza\Working\Source\Remot
> eNet.Zapenza.Web.UI\DevCenter\ApplicationErrorTest.aspx.cs:line 24
> --- End of inner exception stack trace --- at 
> DevCenter_ApplicationErrorTest.lnkApplicationError_Click(Objec
> t sender, EventArgs e) in 
> c:\Solutions\CIProjects\RemoteNet\Zapenza\Working\Source\Remot
> eNet.Zapenza.Web.UI\DevCenter\ApplicationErrorTest.aspx.cs:lin
> e 28 at 
> System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e) at 
> System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String
>  eventArgument) at 
> System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEv
> entHandler.RaisePostBackEvent(String eventArgument) at 
> System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler 
> sourceControl, String eventArgument) at 
> System.Web.UI.Page.RaisePostBackEvent(NameValueCollection 
> postData) at System.Web.UI.Page.ProcessRequestMain(Boolean 
> includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
> 

Mime
View raw message