Update message format of exception logging

Topics: Exception Handling Application Block
May 25, 2011 at 7:33 PM

I'd like to customize what gets put into my database when logging an exception.  Here is my current formatter:

 <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging"
        template="Timestamp: {timestamp}&#xD;&#xA;{message}&#xD;&#xA;Title: {title}&#xD;&#xA;Machine: {machine}&#xD;&#xA;Application Domain: {appDomain}&#xD;&#xA;)}"
        name="Database Formatter" />

It seems the 'message' item puts in a bunch of data.  For me, the data that is added for the 'message' part of the template is:

Details: HandlingInstanceID: acc5f7f2-dc8c-4fc9-ac26-59059d691a6e An exception of type 'System.Exception' occurred and was caught. ---------------------------------------------------------------- 05/25/2011 12:42:07 Type : System.Exception, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089 Message : UserID: Me   Level: Critical   Message: YOYOYO   Stack Trace: This is the stack trace.     Source :   Help link :   Data : System.Collections.ListDictionaryInternal TargetSite :   Stack Trace : The stack trace is unavailable. Additional Info:   MachineName : BGORTER03469 TimeStamp : 5/25/2011 5:42:07 PM FullName : Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 AppDomainName : /LM/W3SVC/1/ROOT/BreezeReview-13-129508189254901213 ThreadIdentity : WindowsIdentity : IIS APPPOOL\32BitEnabledPool  

I would like to remove so of these values.  Anyone have any clue how to get that done?


May 26, 2011 at 4:42 AM


Aside from the Text Formatter from the Logging Block, the Exception Logging Handler also add its own formatter to the message. The structure of message will look like this:

{Exception Formatter}
Additional Info:
{Text Formatter}

You need to create your own implementation of TextExceptionFormatter to be able to customize its content. You can refer here on how to create your own Exception Formatter.


Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.

May 26, 2011 at 2:57 PM

Worked like a charm...thanks!!!