ExceptionPolicy.HandleException not working

Topics: Exception Handling Application Block, General discussion
Apr 13, 2009 at 10:22 PM
The ExceptionPolicty is not working our testing environment but its working on the development environment.

Its not creating the file ROP.log.

The web application already has permissions to me,  and I am admin on the test machine, I also gave Full Permissions to the folder of the webapplication to me.

This is the code in the APplication Error on the global.asax

 void Application_Error(object sender, EventArgs e)
    {
        Exception ex = Server.GetLastError().GetBaseException();
        EPM.Aguas.ROP.Soporte.Framework.Logging.Log.AtraparExcepcion(
            ex,
            EPM.Aguas.ROP.Soporte.Framework.Enumeraciones.TipoPoliticasExcepcion.Presentacion,
            false);
    }


public static void AtraparExcepcion(Exception ex, TipoPoliticasExcepcion tipoPolitica, bool lanzarException)
      {
         bool blnResult = false;

         try
         {
            blnResult = ExceptionPolicy.HandleException(
               ex,
               tipoPolitica.ToString());
         }
         catch (Exception ex2)
         {
            Log.EscribirLogEventos(ex);
            Log.EscribirLogEventos(ex2);
         }

         if (lanzarException)
         {
            throw ex;
         }
      }



And the web.config
<configSections>
    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </configSections>
  <loggingConfiguration name="Logging Application Block" tracingEnabled="true"
    defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
    <listeners>
      <add fileName="Log\autenticacion.log" header="----------------------------------------"
        footer="----------------------------------------" formatter="LogAutenticacion"
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="FlatFile Autenticacion" />
      <add fileName="Log\ROP.log" header="----------------------------------------"
        footer="----------------------------------------" formatter="Text Formatter"
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="FlatFile TraceListener" />
    </listeners>
    <formatters>
      <add template="Autenticación ROP&#xA;Fecha: {timestamp}&#xA;{dictionary({key}: {value}&#xA;)}"
        type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="LogAutenticacion" />
      <add template="Timestamp: {timestamp}&#xA;Message: {message}&#xA;Category: {category}&#xA;Priority: {priority}&#xA;EventId: {eventid}&#xA;Severity: {severity}&#xA;Title:{title}&#xA;Machine: {machine}&#xA;Application Domain: {appDomain}&#xA;Process Id: {processId}&#xA;Process Name: {processName}&#xA;Win32 Thread Id: {win32ThreadId}&#xA;Thread Name: {threadName}&#xA;Extended Properties: {dictionary({key} - {value}&#xA;)}"
        type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="Text Formatter" />
    </formatters>
    <categorySources>
      <add switchValue="All" name="Autenticacion">
        <listeners>
          <add name="FlatFile Autenticacion" />
        </listeners>
      </add>
      <add switchValue="All" name="AutenticacionFallida">
        <listeners>
          <add name="FlatFile Autenticacion" />
        </listeners>
      </add>
      <add switchValue="All" name="Presentacion">
        <listeners>
          <add name="FlatFile TraceListener" />
        </listeners>
      </add>
      <add switchValue="All" name="General">
        <listeners>
          <add name="FlatFile TraceListener" />
        </listeners>
      </add>
    </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="FlatFile Autenticacion" />
          <add name="FlatFile TraceListener" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>


Thanks
Apr 14, 2009 at 1:51 AM
Do they have the same OS?  If not, what's the OS for each environment?  Please also include your exceptionhandling configuration section. 


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com
Apr 14, 2009 at 2:25 PM
Both are Windows XP.

And this is the Exception handling.


Thank you

<exceptionHandling>
    <exceptionPolicies>
      <add name="Presentacion">
        <exceptionTypes>
          <add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            postHandlingAction="NotifyRethrow" name="Exception">
            <exceptionHandlers>
              <add logCategory="General" eventId="100" severity="Error" title="Enterprise Library Exception Handling"
                formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                priority="0" useDefaultLogger="false" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                name="Logging Handler" />
            </exceptionHandlers>
          </add>
        </exceptionTypes>
      </add>
    </exceptionPolicies>
Apr 15, 2009 at 4:17 AM
Hi,

Your code and config seems fine, tried it on a dev environment and its working. Anyway, I experienced this problem before but on Windows Server 2008, where my expected log file was not created. So what I did is to set the permission to "Everyone" and "Give it full control" to the folder where the log file will be created. In your case, I think you should set the permission to the folder where the Log\ROP.log will be created. 


Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com
Apr 15, 2009 at 1:45 PM
I found this exception on the eventlog.

I think thats why its not working,

The current build operation (build key Build Key[Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyImpl, Presentacion]) failed: The type 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' cannot be resolved. Please verify the spelling is correct or that the full type name is provided. (Strategy type Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfiguredObjectStrategy, index 2)



Apr 16, 2009 at 3:05 AM
Ah,  you need to add the ExceptionHandling.Logging assembly.  But I don't get it if it's working on your dev environment.  If you didn't add reference to it, you should be getting the same exception.  Is entlib installed in the test environment?  If not, how did you referenced the entlib assemblies from your solution?  Did you add reference from the entlib installation folder?


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com
Apr 16, 2009 at 7:00 PM
We already fixed this, but it was very difficult to find the solution.

The problem was that we were referencing the Dlls on the folder C:\EntlibSrc\bin, and once we deleted those references and added the strong named ones from C:\Program Files\etc  it worked right away,.



Thanks
Apr 20, 2009 at 1:13 AM
It should have thrown the same exception in the same environment.  Anyway, glad you've already fixed this.


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com