サンプルアプリとまったく同じように ELMAH をセットアップしました。以下を使用して、ELMAH をテストするためにエラーをスローしようとしました。
throw new InvalidOperationException();
残念ながら、私のアプリはエラーに直行しており、ELMAH はエラーをキャッチ/ログしていません。ASP.NET 3.5 を使用しています。Web.Config はサンプルとまったく同じであるため、何が間違っているのかわかりません
Web.config を再確認してください。モジュールを登録するのを忘れたことに気付くまで、同じ問題がありました。
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
dotnetslackersに関するこの記事が役に立ちました。
Elmah はオープン ソースであるため、コードをプロジェクトとしてソリューションに追加し、すべての例外でビジュアル スタジオを中断する必要があります。Elmah が飲み込んでしまう例外をスローしている可能性はありそうです。これとまったく同じことが私に起こっていて、エラーを挿入するストアド プロシージャのアクセス許可でした。
ORIGINAL
テストは 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>