Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elmah: ErrorLog_Filtering event handler not called under IIS7

I enable error log filtering within Elmah and want to do it programmatically in a ErrorLog_Filtering event handler. It works well under Visual Studio dev server but as soon as I go under IIS7 (local on my dev machine or remote on my web server), the handler is not called (error logging works well).

Here is my usual web.config:

<configuration>

  <configSections>

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

  <elmah>
    <errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="ShopMvcConnectionString" />
  </elmah>

  <system.web>

    <httpHandlers>
      <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
    </httpHandlers>

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

  </system.web>

  <system.webServer>

    <modules runAllManagedModulesForAllRequests="true">
      <add name="Elmah.ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
      <add name="Elmah.ErrorFilter" type="Elmah.ErrorFilterModule" preCondition="managedHandler" />
    </modules>

    <handlers>
      <add name="Elmah" path="elmah.axd" verb="POST,GET,HEAD" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode" />
    </handlers>
  </system.webServer>

</configuration>

and my handler in Global.asax:

public void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e)
{
}
like image 402
Nicolas Cadilhac Avatar asked Dec 07 '25 09:12

Nicolas Cadilhac


1 Answers

The reason your handler in not being called under IIS 7 is because you named the module differently. You named it ErrorLog under system.web/httpModules and then Elmah.ErrorLog under system.webServer/modules.

Handling module events in Global.asax works via a naming convention where the event handler must be named after the module name as found in the configuration followed by an underscore (_), followed by the event name. ErrorLog_Filtering is fine and matches the registered name under system.web/httpModules and which is being picked up by the Visual Studio Development Server. You just need to make sure that you match up all the names and it should work in both environments.

See also: Programmatically log error and send email

like image 55
Atif Aziz Avatar answered Dec 08 '25 22:12

Atif Aziz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!