ExceptionPolicy.Handle Exception is not working for me.

Topics: Exception Handling Application Block
Aug 27, 2010 at 2:22 PM

 I have the following configuration in my app.config of windows service.

When i call like a following from my windows service, i dont see any entry in the exception log file. There is other exception throws out. Exception Handling Block is supressing the exception without logging to the file? Please help me. I dont know how to go about this issue...

try

{}

catch(Exception ex)

{

Exception Policy.HandleException(ex, "BatchProcessException");

}

 <loggingConfiguration name="Logging Application Block" tracingEnabled="true"
    defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
    <listeners>
      <add name="Rolling Flat File Exception TraceListener" fileName="c:\logs\BatchExceptions.log" formatter="" rollInterval="Day" rollSizeKB="5000" traceOutputOptions="None"
        timeStampPattern="dd-MM-yyyy" rollFileExistsBehavior="Increment" header="--------------------Begin Log Entry--------------------" footer="--------------------End Log Entry--------------------"
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging"
        type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging" />
      <add name="Formatted EventLog TraceListener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging"
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging"
        source="Enterprise Library Logging" formatter="Text Formatter"
        log="Application" machineName="" traceOutputOptions="None" filter="All" />
      <add name="Rolling Flat File General TraceListener" fileName="c:\logs\BatchTrace.log" formatter="Text Formatter" rollInterval="Week" rollSizeKB="5000" traceOutputOptions="None"
        timeStampPattern="dd-MM-yyyy" rollFileExistsBehavior="Increment" header="--------------------Begin Log Entry--------------------" footer="--------------------End Log Entry--------------------"
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging"
        type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging" />
      <add name="Email Alerts" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.EmailTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging"
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.EmailTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging"
        toAddress="pveeras@transunion.com" fromAddress="idssupport@transunion.com"
        subjectLineStarter="DecisionCentre Batch System Alert" subjectLineEnder=""
        smtpServer="TUCOSI380.ads.vsi.com" smtpPort="25" formatter="Text Formatter"
        traceOutputOptions="None" />
    </listeners>
    <formatters>
      <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging"
        template="Timestamp: {timestamp}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;EventId: {eventid}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Title:{title}&#xD;&#xA;Machine: {machine}&#xD;&#xA;Application Domain: {appDomain}&#xD;&#xA;Process Id: {processId}&#xD;&#xA;Process Name: {processName}&#xD;&#xA;Win32 Thread Id: {win32ThreadId}&#xD;&#xA;Thread Name: {threadName}&#xD;&#xA;Extended Properties: {dictionary({key} - {value}&#xD;&#xA;)}"
        name="Text Formatter" />
    </formatters>
    <categorySources>
      <add switchValue="All" name="Exceptions">
        <listeners>
          <add name="Rolling Flat File Exception TraceListener" />
        </listeners>
      </add>
      <add switchValue="All" name="General">
        <listeners>
          <add name="Rolling Flat File General TraceListener" />
        </listeners>
      </add>
      <add switchValue="All" name="Alerts" />
    </categorySources>
    <specialSources>
      <allEvents switchValue="All" name="All Events" />
      <notProcessed switchValue="All" name="Unprocessed Category" />
      <errors switchValue="All" name="Logging Errors &amp; Warnings">
        <listeners>
          <add name="Formatted EventLog TraceListener" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>
  <exceptionHandling>
    <exceptionPolicies>
      <add name="ServiceExceptionHandling">
        <exceptionTypes>
          <add name="Exception" type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            postHandlingAction="NotifyRethrow">
            <exceptionHandlers>
              <add name="Logging Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging"
                logCategory="Exceptions" eventId="100" severity="Error" title="Enterprise Library Exception Handling"
                formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"
                priority="0" useDefaultLogger="false" />
            </exceptionHandlers>
          </add>
        </exceptionTypes>
      </add>
      <add name="BatchProcessException">
        <exceptionTypes>
          <add name="Exception" type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            postHandlingAction="NotifyRethrow">
            <exceptionHandlers>
              <add name="Logging Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging"
                logCategory="Exceptions" eventId="100" severity="Error" title="Enterprise Library Exception Handling"
                formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"
                priority="0" useDefaultLogger="false" />
            </exceptionHandlers>
          </add>
        </exceptionTypes>
      </add>
      <add name="FilePolicyException">
        <exceptionTypes>
          <add name="Exception" type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            postHandlingAction="NotifyRethrow">
            <exceptionHandlers>
              <add name="Logging Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging"
                logCategory="Exceptions" eventId="100" severity="Error" title="Enterprise Library Exception Handling"
                formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"
                priority="0" useDefaultLogger="false" />
            </exceptionHandlers>
          </add>
        </exceptionTypes>
      </add>
    </exceptionPolicies>
  </exceptionHandling>

Aug 31, 2010 at 3:31 AM

Hi kannan1017,

Were there any exception raised during execution? I've tried to reproduce your problem by copy/paste your configuration but unfortunately it works from my end. One more questions is do you have a proper permission to write in the directory you specified in your rolling flat file tracelistener (c:\logs\BatchExceptions.log)?

Gino Terrado
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com