Formatting the errors on the log file

Topics: Exception Handling Application Block, Logging Application Block
Mar 19, 2011 at 3:56 PM

I am writing my errors to a log file using Enterprise Library 5.0. The format of the error message is horrible. I use to use Enterprise Library 2.0 and the formating was 100 times better than what I am getting now. Is there way I can format my errors better? Bellow is a sample of what I am getting? Also there are three different time stamps on there and two of them are not correct. How can fix it? It is so confusing when go through my log file trying to figure out which error is the correct one I am looking for.

----------------------------------------
General Error: 100 : Timestamp: 3/19/2011 3:41:25 PM
Message: HandlingInstanceID: 501383a3-ce23-47ea-bc25-752720815ce2
An exception of type 'System.ArgumentException' occurred and was caught.
------------------------------------------------------------------------
03/19/2011 11:41:25
Type : System.ArgumentException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : Parameter is not valid.
Source : System.Drawing
Help link :
ParamName :
Data : System.Collections.ListDictionaryInternal
TargetSite : Void .ctor(System.String)
Stack Trace :    at System.Drawing.Bitmap..ctor(String filename)
   at Molding.frmInjection.DisplayPartImage() in C:\Users\User\Documents\Visual Studio 2010\Line Side Labeling\T0A\T0A Molding Main\Molding Single Part\frmInjection.vb:line 1849

Additional Info:

MachineName : FERNANDO-7
TimeStamp : 3/19/2011 3:41:25 PM
FullName : Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
AppDomainName : Molding.vshost.exe
ThreadIdentity :
WindowsIdentity : HQPROD\User

Category: General
Priority: 0
EventId: 100
Severity: Error
Title:Enterprise Library Exception Handling
Machine: FERNANDO-7
App Domain: Molding.vshost.exe
ProcessId: 5364
Process Name: C:\Users\User\Documents\Visual Studio 2010\Line Side Labeling\T0A\T0A Molding Main\Molding Single Part\bin\Molding.vshost.exe
Thread Name:
Win32 ThreadId:636
Extended Properties:
----------------------------------------

Mar 21, 2011 at 5:41 AM

Hi,

You can customize the part:

MachineName : FERNANDO-7
TimeStamp : 3/19/2011 3:41:25 PM
FullName : Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
AppDomainName : Molding.vshost.exe
ThreadIdentity :
WindowsIdentity : HQPROD\User

Category: General
Priority: 0
EventId: 100
Severity: Error
Title:Enterprise Library Exception Handling
Machine: FERNANDO-7
App Domain: Molding.vshost.exe
ProcessId: 5364
Process Name: C:\Users\User\Documents\Visual Studio 2010\Line Side Labeling\T0A\T0A Molding Main\Molding Single Part\bin\Molding.vshost.exe
Thread Name:
Win32 ThreadId:636
Extended Properties:

since it uses the formatter configured on your Logging Application Block. The timestamp here is shown in UTC format.  You can use "{timestamp(local)}" token to output the local datetime. Meanwhile, the format:

----------------------------------------
General Error: 100 : Timestamp: 3/19/2011 3:41:25 PM
Message: HandlingInstanceID: 501383a3-ce23-47ea-bc25-752720815ce2
An exception of type 'System.ArgumentException' occurred and was caught.
------------------------------------------------------------------------
03/19/2011 11:41:25
Type : System.ArgumentException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : Parameter is not valid.
Source : System.Drawing
Help link :
ParamName :
Data : System.Collections.ListDictionaryInternal
TargetSite : Void .ctor(System.String)
Stack Trace :    at System.Drawing.Bitmap..ctor(String filename)
   at Molding.frmInjection.DisplayPartImage() in C:\Users\User\Documents\Visual Studio 2010\Line Side Labeling\T0A\T0A Molding Main\Molding Single Part\frmInjection.vb:line 1849

was taken care by the Logging Exception Handler. If you want to customize this format, you need to use a custom Exception Formatter (you can refer here on how to Create a Custom Exception Formatter) . Regarding the timestamp, you need to write a method inside the custom exception formatter to display the local datetime. A similar discussion is posted here. Hope this helps.

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com