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

发布于 2024-09-17 09:13:00 字数 2133 浏览 7 评论 0原文

我在 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>

和 Global.asax 中的处理程序:

public void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e)
{
}

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)
{
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如痴如狂 2024-09-24 09:13:01

您的处理程序在 IIS 7 下未被调用的原因是您对模块的命名不同。您将其命名为 system.web/httpModules 下的 ErrorLog,然后将其命名为 system.webServer/modules 下的 Elmah.ErrorLog

处理 Global.asax 中的模块事件 通过命名约定工作,其中事件处理程序必须以配置中找到的模块名称命名,后跟下划线 (_),后跟事件名称。 ErrorLog_Filtering 很好,并且与 system.web/httpModules 下的注册名称相匹配,并且 Visual Studio 开发服务器。您只需要确保匹配所有名称,并且它应该在两种环境中都有效。

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文