1

を使用するのは初めてですELMAHが、GUIDをエラーページに渡してみたいと思います。

この記事で説明したことを試しましたが、ErrorLog_Loggedを起動できません。これが発生している理由のアイデア。web.configファイルにいくつかの構成を追加する必要がありますか?(以下のコードのフォーマットについては事前に申し訳ありませんが、正しく表示されません)。

ありがとうございました、

これが私のweb.configファイルの内容です:

<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="telerik.web.ui">
        <section name="radScheduler" type="Telerik.Web.UI.RadSchedulerConfigurationSection, Telerik.Web.UI" allowDefinition="MachineToApplication" requirePermission="false"/>
        <section name="radCompression" type="Telerik.Web.UI.RadCompressionConfigurationSection, Telerik.Web.UI, PublicKeyToken=121fae78165ba3d4" allowDefinition="MachineToApplication" requirePermission="false"/>
    </sectionGroup>
<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"/>
</sectionGroup>


これが私のglobal.asaxファイルの内容です

void ErrorLog_Logged(object sender, ErrorLoggedEventArgs args)
{
    //if (args.Entry.Error.Exception is HandledElmahException)
    //    return;

    var config = WebConfigurationManager.OpenWebConfiguration("~");
    var customErrorsSection = (CustomErrorsSection)config.GetSection("system.web/customErrors");

    if (customErrorsSection != null)
    {
        switch (customErrorsSection.Mode)
        {
            case CustomErrorsMode.Off:
                break;
            case CustomErrorsMode.On:
                FriendlyErrorTransfer(args.Entry.Id, customErrorsSection.DefaultRedirect);
                break;
            case CustomErrorsMode.RemoteOnly:
                if (!HttpContext.Current.Request.IsLocal)
                    FriendlyErrorTransfer(args.Entry.Id, customErrorsSection.DefaultRedirect);
                break;
            default:
                break;
        }
    }
}

void FriendlyErrorTransfer(string emlahId, string url)
{
    Response.Redirect(String.Format("{0}?id={1}", url, Server.UrlEncode(emlahId)));
}
4

1 に答える 1

1

web.configで、次のことを確認してください

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

すなわち

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

また、追加します

Elmah.ErrorLogModule logModule = new Elmah.ErrorLogModule();
logModule.Logged += new Elmah.ErrorLoggedEventHandler(logModule_Logged);
Elmah.ErrorSignal.FromCurrentContext().Raise(ex); 

あなたのApplication_Error機能に。

于 2012-07-09T22:27:18.263 に答える