首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ELMAH :引发ErrorLog_Logged事件

ELMAH :引发ErrorLog_Logged事件
EN

Stack Overflow用户
提问于 2012-07-10 06:15:40
回答 1查看 1.4K关注 0票数 1

我刚开始使用ELMAH,但我想尝试将GUID传递给错误页面。

我尝试了this文章中提到的内容,但我无法启动ErrorLog_Logged。你知道为什么会发生这种情况吗?我是否需要在web.config文件中添加一些额外的配置?(为下面代码的格式提前道歉,无法使其正确显示)。

谢谢,

下面是我的web.config文件的内容:

代码语言:javascript
复制
<?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文件的内容

代码语言:javascript
复制
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)));
}
EN

回答 1

Stack Overflow用户

发布于 2012-07-10 06:27:18

在你的web.config中,确保你有

代码语言:javascript
复制
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />

i.e

代码语言:javascript
复制
<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>

还可以添加

代码语言:javascript
复制
Elmah.ErrorLogModule logModule = new Elmah.ErrorLogModule();
logModule.Logged += new Elmah.ErrorLoggedEventHandler(logModule_Logged);
Elmah.ErrorSignal.FromCurrentContext().Raise(ex); 

添加到您的Application_Error函数。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11403983

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档