Dkong
Dkong

Reputation: 2788

ELMAH setup - errors not being caught

I've setup ELMAH exactly as with the sample app. I attempt to throw an error to test ELMAH by using:

throw new InvalidOperationException();

Unfortunately however my app is going straight to the error and ELMAH is not catching/logging the error. I am using ASP.NET 3.5. I am not sure what I am doing wrong as the Web.Config is exactly the same as the sample

Upvotes: 2

Views: 1968

Answers (2)

RSolberg
RSolberg

Reputation: 26972

Since Elmah is open source, you should add the code as a project in your solution and make sure that you have visual studio break on all exceptions. It sounds feasible that Elmah is throwing an Exception which would be swallowed. This exact thing was happening with me and it was a permission on the stored procedure that inserts the error.

ORIGINAL
Is your test within a try/catch block? If so, you'll have to explicitly force the logging to occur.

Elmah.ErrorSignal.FromCurrentContext().Raise(ex);

MY WEB.CONFIG SETUP

  <configSections>
    <sectionGroup name="elmah">
      <section name="security" type="Elmah.SecuritySectionHandler, Elmah"/>
      <section name="errorLog" type="Elmah.ErrorLogSectionHandler, Elmah" />
      <section name="errorMail" type="Elmah.ErrorMailSectionHandler, Elmah" />
      <section name="errorFilter" type="Elmah.ErrorFilterSectionHandler, Elmah"/>
    </sectionGroup>
   ...
   </configSections>

  <elmah>
    <security allowRemoteAccess="0" />
    <errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="TESTElmahConnectionString" />
    <errorFilter>
      <test>
        <equal binding="HttpStatusCode" value="404" type="Int32" />
      </test>
    </errorFilter>
  </elmah>


<httpModules>
  <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
  <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah"/>
  <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah"/>
  <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpModules>

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules>
      <remove name="ScriptModule"/>
      <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
      <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />
      <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" />
    </modules>
    <handlers>
      <remove name="WebServiceHandlerFactory-Integrated"/>
      <remove name="ScriptHandlerFactory"/>
      <remove name="ScriptHandlerFactoryAppServices"/>
      <remove name="ScriptResource"/>
      <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    </handlers>
  </system.webServer>

Upvotes: 2

Mattio
Mattio

Reputation: 2032

Double check your Web.config. I had the same problem until I realized I forgot to register the module.

<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />

I found this article over on dotnetslackers helpful.

Upvotes: 5

Related Questions