Ent.Lib 4.0 Exceptions not going to same file as normal logging

Topics: Exception Handling Application Block, Logging Application Block
Dec 9, 2012 at 9:16 PM
Edited Dec 9, 2012 at 9:17 PM

Hi All,

Am working on a solution that uses "Ent.Lib 4.0". 

I want logging and exception handling to go to the same file but when an exception is thown a new separate file is created.

How can i make Exception Handler & Logger use the same log writer??

In "Ent.Lib 5.1" I use the following to achieve this...

_traceManager = EnterpriseLibraryContainer.Current.GetInstance<TraceManager>();
...
_traceManager.LogWriter.Write...

Is this possible in 4.1 and if so what is the syntax?

 

Dec 9, 2012 at 11:18 PM
Edited Dec 9, 2012 at 11:20 PM

This is the expected behavior when useDefaultLogger is set to false (the default).  From the release notes:

The Logging Handler has a new Boolean property named UseDefaultLogger. When set to True, the handler writes every log event and exception to the same file. When set to False (the default) it writes log event and exception information to separate files named with a GUID.

So change the configuration to set useDefaultLogger to true:

  <exceptionHandling>
    <exceptionPolicies>
      <add name="Policy">
        <exceptionTypes>
          <add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            postHandlingAction="NotifyRethrow" name="Exception">
            <exceptionHandlers>
              <add logCategory="Error" eventId="100" severity="Error" title="Enterprise Library Exception Handling"
                formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                priority="0" useDefaultLogger="true" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                name="Logging Handler" />
            </exceptionHandlers>
          </add>
        </exceptionTypes>
      </add>
    </exceptionPolicies>
  </exceptionHandling>

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com 

Dec 10, 2012 at 1:51 AM

Hi Randy,

Thanks for that, it was exactly what i was looking for.

Cheers,

Ken