Exception Block not playing with Logging block

Topics: Exception Handling Application Block, Logging Application Block
Sep 12, 2008 at 2:31 PM
Hi,

I have a very simple app that uses the Exception App Block and the Logging block.

I set the app up so that I have a method that is invoked from a button click handler. The method is intened to perform a divide by zero. I thought I would also use the logging block to write out some debug messages. The Form class looks like:

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                // Comment this out to only get the Exception block handler exception
                Logger.Write("Calling method");
                NewMethod();
            }
            catch (Exception ex)
            {
                Logger.Write("Got an exception in the UI, ", "General");
            }
        }

        private static void NewMethod()
        {
            try
            {
                int z = 0;
                int i = 1 / z;
            }
            catch (Exception ex)
            {
                if(ExceptionPolicy.HandleException(ex, "Policy 1"))
                    throw ex;
            }
        }
    }

The problem I'm having is that if I comment out the first Logger.Write() call in the button handler I get the Exception logged ok, but I never get the second message in the log file from the second Logger.Write().

If I leave the initial Logger.Write() call in, then I only get the two Logger.Write() message in my output file and not the Exception block message.

For example, the code above has both Logger.Write calls in and gives the following trace file:
----------------------------------------
Timestamp: 12/09/2008 13:20:39
Message: Calling method
Category: General
Priority: -1
EventId: 1
Severity: Information
Title:
Machine: XYZ
Application Domain: WindowsFormsApplication6.vshost.exe
Process Id: 1176
Process Name: E:\Data\Temp\WindowsFormsApplication6\WindowsFormsApplication6\bin\Debug\WindowsFormsApplication6.vshost.exe
Win32 Thread Id: 4592
Thread Name:
Extended Properties:
----------------------------------------
----------------------------------------
Timestamp: 12/09/2008 13:20:40
Message: Got an exception in the UI,
Category: General
Priority: -1
EventId: 1
Severity: Information
Title:
Machine: XYZ
Application Domain: WindowsFormsApplication6.vshost.exe
Process Id: 1176
Process Name: E:\Data\Temp\WindowsFormsApplication6\WindowsFormsApplication6\bin\Debug\WindowsFormsApplication6.vshost.exe
Win32 Thread Id: 4592
Thread Name:
Extended Properties:
----------------------------------------

If I comment of the first Logger.Write() call my trace file looks like:

----------------------------------------
Timestamp: 12/09/2008 13:21:37
Message: HandlingInstanceID: 623372e6-aafa-4d9f-a534-4b7b2f5f8ef2
An exception of type 'System.DivideByZeroException' occurred and was caught.
----------------------------------------------------------------------------
09/12/2008 14:21:37
Type : System.DivideByZeroException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : Attempted to divide by zero.
Source : WindowsFormsApplication6
Help link :
Data : System.Collections.ListDictionaryInternal
TargetSite : Void NewMethod()
Stack Trace :    at WindowsFormsApplication6.Form1.NewMethod() in E:\Data\Temp\WindowsFormsApplication6\WindowsFormsApplication6\Form1.cs:line 41

Additional Info:

MachineName : XYZ
TimeStamp : 12/09/2008 13:21:37
FullName : Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
AppDomainName : WindowsFormsApplication6.vshost.exe
ThreadIdentity :
WindowsIdentity : me

Category: ExceptionCategory
Priority: 0
EventId: 100
Severity: Error
Title:Enterprise Library Exception Handling
Machine: XYZ
Application Domain: WindowsFormsApplication6.vshost.exe
Process Id: 2752
Process Name: E:\Data\Temp\WindowsFormsApplication6\WindowsFormsApplication6\bin\Debug\WindowsFormsApplication6.vshost.exe
Win32 Thread Id: 4268
Thread Name:
Extended Properties:
----------------------------------------



Am I doing something wrong?

Graham

Sep 12, 2008 at 2:58 PM
Interesting! If I use a DebugTraceListener instead of the Flat File Trace Listener I get to see all me messages.

Graham