1

I'm new to using ELMAH, but I want to try to pass the GUID to the error page.

I tried what this article talked about and I can't get the ErrorLog_Logged to fire. Any ideas why this is occuring. Do I need to add some additional configuration to the web.config file? (Sorry in advance for the formatting of the code below, can't make it show up correctly).

Thank you,

Here is the contents of my web.config file:

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


Here is the contents of my global.asax file

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)));
}
Community
  • 1
  • 1
MindGame
  • 1,211
  • 6
  • 29
  • 50

1 Answers1

1

In your web.config ensure that you have

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

i.e

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

Also add

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

to your Application_Error function.

John Mitchell
  • 9,653
  • 9
  • 57
  • 91
  • Thanks for the quick reply. Yes I have that in the web.config file for the modules tag. – MindGame Jul 09 '12 at 22:34
  • The only thing I did not have is runAllManagedModulesForAllRequests="true", I added that in and no luck still.Any ideas? – MindGame Jul 09 '12 at 22:40
  • 1
    Afraid not the ErrorLog is the module that sends out the events so hooking into ErrorLog_Logged should of done it. Sorry! – John Mitchell Jul 09 '12 at 22:54
  • I'm using VS2010, would that make a difference? You think it would help showing you my entire web.config file? – MindGame Jul 09 '12 at 22:55
  • 1
    No the edition of Visual Studio shouldn't make a difference since the code is run by the server (or development server) – John Mitchell Jul 09 '12 at 22:56
  • I'm running it locally from VS2010, should that matter? I put a break point in the global.asax. – MindGame Jul 09 '12 at 22:57
  • I added my web.config file, does not show up though. If you click on edit you can see it them. Sorry again for the formatting. – MindGame Jul 09 '12 at 22:59
  • 1
    change errorLog to ErrorLog since this is converted into a type capitalization will make a difference. – John Mitchell Jul 09 '12 at 23:01
  • So change this and
    ?
    – MindGame Jul 09 '12 at 23:03
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/13638/discussion-between-john-mitchell-and-tesh) – John Mitchell Jul 09 '12 at 23:05
  • So you told me to add Application_Error ... { Elmah.ErrorLogModule logModule = new Elmah.ErrorLogModule(); logModule.Logged += new Elmah.ErrorLoggedEventHandler (logModule_Logged); Elmah.ErrorSignal.FromCurrentContext().Raise(ex); } – MindGame Jul 09 '12 at 23:28
  • 1
    Its the exception thats raised from Application_Error you could remove that line. – John Mitchell Jul 09 '12 at 23:34
  • This is what i have in my Application_Error void Application_Error(object sender, EventArgs e) { Elmah.ErrorLogModule logModule = new Elmah.ErrorLogModule(); logModule.Logged += new Elmah.ErrorLoggedEventHandler(ErrorLog_Logged); System.Web.HttpContext context = HttpContext.Current; System.Exception ex = Context.Server.GetLastError(); Elmah.ErrorSignal.FromCurrentContext().Raise(ex); } – MindGame Jul 10 '12 at 03:28
  • I was sure this would work. If you have any more ideas let me know. – MindGame Jul 10 '12 at 03:29
  • if this matter i see this in the error url : http://localhost:2941/genpns/error.aspx?aspxerrorpath=/GenPNS/default.aspx – MindGame Jul 10 '12 at 03:57
  • So I got the event to fire now. If I remove from the tags . I was using this to log to the database. So how would I log the messages now? Manually? – MindGame Jul 10 '12 at 20:24
  • I created a new ticket for this http://stackoverflow.com/questions/11422681/elmah-not-logging-correctly – MindGame Jul 10 '12 at 23:23