ELMAH 设置 - 错误未被捕获

发布于 2024-08-03 18:00:39 字数 213 浏览 6 评论 0原文

我已经按照示例应用程序完全设置了 ELMAH。我尝试使用以下方法抛出错误来测试 ELMAH:

throw new InvalidOperationException();

不幸的是,我的应用程序直接出现错误,而 ELMAH 没有捕获/记录错误。我正在使用 ASP.NET 3.5。我不确定我做错了什么,因为 Web.Config 与示例完全相同

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

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

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

发布评论

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

评论(2

银河中√捞星星 2024-08-10 18:00:39

仔细检查您的 Web.config。我遇到了同样的问题,直到我意识到我忘记注册模块。

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

我发现 dotnetslackers 上的这篇文章很有帮助。

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.

治碍 2024-08-10 18:00:39

由于 Elmah 是开源的,因此您应该将代码作为项目添加到解决方案中,并确保 Visual Studio 能够中断所有异常。 Elmah 抛出一个会被吞掉的异常听起来是可行的。这正是发生在我身上的事情,这是插入错误的存储过程的权限。

原创
您的测试是否在 try/catch 块内?如果是这样,您必须显式强制进行日志记录。

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

我的WEB.CONFIG设置

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

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