Elmah:在IIS7下未调用ErrorLog_Filtering事件处理程序

Nic*_*hac 2 asp.net elmah web-config

我在Elmah中启用了错误日志过滤,并希望在ErrorLog_Filtering事件处理程序中以编程方式执行此操作.它在Visual Studio开发服务器下运行良好,但是一旦我进入IIS7(我的开发机器本地或我的Web服务器上的远程),就不会调用处理程序(错误日志记录工作正常).

这是我通常的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>
Run Code Online (Sandbox Code Playgroud)

和我在Global.asax中的处理程序:

public void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e)
{
}
Run Code Online (Sandbox Code Playgroud)

Ati*_*ziz 8

您的处理程序未在IIS 7下调用的原因是您不同方式命名模块.你把它命名为ErrorLogsystem.web/httpModules,然后Elmah.ErrorLogsystem.webServer/modules.

Global.asax通过命名约定处理模块事件,其中事件处理程序必须在配置中找到的模块名称之后命名,后跟一个下划线(_),后跟事件名称.ErrorLog_Filtering没问题,并且与Visual Studio开发服务器system.web/httpModules正在接收的注册名称相匹配.您只需要确保匹配所有名称,它应该适用于两种环境.

另请参阅:以编程方式记录错误并发送电子邮件