tags:

views:

296

answers:

2

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

+2  A: 

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>
RSolberg
no try catch block yet. i am just looking to get the basic default handling working before i try signaling
Dkong
+1 for the include the source code into the project.
melaos
+1  A: 

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.

Mattio
i've got that line, but still no joy.
Dkong
Doh, I was missing this line. It was particularly vexing because it worked in dev, but I'm on IIS 7 in dev, IIS 6 in prod...I wonder why I didn't need it in IIS? Either way, thanks, this was exactly it.
CubanX