Customising Exception formatting with EL Jan2006

Topics: Exception Handling Application Block, Logging Application Block
Jul 6, 2009 at 1:10 PM
Edited Jul 6, 2009 at 2:48 PM


I am using .net framework 2.0 and EL Jan 2006 and EHAB. I'm confused (again). I'm using a Formatted event log trace listener and database trace listener.

I have read that the Logging Exception Handler uses a TextExceptionFormatter. Apparently this formats the exception info such as the message and the stack trace and then passes it to the Logging Application Block. This formatted exception info is then displayed in the message field of the template used by the TraceListener'sTextFormatter.

I would like to modify the exception handling block so that it handles inner exceptions (i was advised that it doesnt handle inner exception in a previous post). I was also told I would need to implement a custom exception handler. I'm a little but confused by this. Couldn't i just subclass the textexceptionformatter? Presumably this has a method called format which takes an exception as a parameter. I could them overwrite the format method to show what information I want and then configure the logging exception handler to use this formatter. Of course if it is hard coded into the logging exception handler  which textexceptionformatter to use then i guess i have no choice but to write a custom exception handler.

Any clarification (and simple examples) would be greatly appreciated.


Jul 7, 2009 at 2:48 AM

The ExceptionFormatter merely handles what information will be log and how it would look like, it doesn't do any exception handling.  In the 4.1 version, it writes the inner exception to as part of the message that is forwarded to the tracelistener.   (You would need to check on the source code of your entlib version, I don't have a copy of it.) How do you want inner exceptions to be handled, anyway?  If you want something other than to write it, you would have to create your own custom exception handler.  The type of formatter is not hardcoded, you can choose from TextExceptionFormatter, XmlExceptionFormatter and your own Custom Formatter.


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.


Jul 13, 2009 at 11:42 PM


I am using the jan 2006 and as far as i can see the TextExceptionFormatter does not write out the inner exceptions.

All i want to do is iterate through the inner exceptions of an exception and output them.  I am confused why i need to write a custom exception handler and why i cant just write a custom Formatter. It is probably based on preconceptions i have that are wrong so i should explain them i think.

I believe the HandleException method of the exception handler class does something like this (in pseudocode)

public HandleException(Exception exception)

//Create log entry and set properties
        LogEntry logEntry = new LogEntry();
        logEntry.Message = TheExceptionFormatter.Format(exception)  <===========MY FORMAT method would be called here
        logEntry.ExtendedProperties = dictionary;

foreach (DictionaryEntry dataEntry in exception.Data)


if (dataEntry.Key is string)


log.ExtendedProperties.Add(dataEntry.Key as string,



        return exception;
If the exception formatter used in configurable then if i write a custom formatter with a format method that outputs 
the inner exception details of the exception pased into it then the format method of that class would be
called where i have indicated above.
Does that make sense? I don't see why i would have to write a custom exception handler if the existing exception
handler has a configurable ExceptionFormatter and i could simply write a subclass that overrides the format method
and then this format method would be called by virtue of polymorphism.
I expeect its my understanding of how the exception handler works that is the problem
mamy thanks
Jul 14, 2009 at 7:29 AM

Yes, your understading is correct.  I was just not sure in your initial post how do you want to "handle inner exceptions".  Since you just want to output them, yes, you could just create a custom exception formatter.


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.