Logged event

143 views
Skip to first unread message

TonyB

unread,
Mar 20, 2009, 4:26:45 PM3/20/09
to ELMAH
Does anyone have any sample code on how to attach to the
ErrorLogModule.Logged event?

I have a custom error page that uses the ID of the log entry and it
seams like that event would be the best place to get that info without
having to modify the ELMAH source.

Atif Aziz

unread,
Mar 23, 2009, 6:02:59 AM3/23/09
to el...@googlegroups.com
>>
I have a custom error page that uses the ID of the log entry and it
seams like that event would be the best place to get that info without
having to modify the ELMAH source.
<<

Yes, the Logged event is really designed to support such a scenario.

> Does anyone have any sample code on how to attach to the
> ErrorLogModule.Logged event?

To tap into it, you need to add an event handler in the Global.asax or its code-behind. The event handler needs to look like this in C#:

void MMM_Logged(object sender, ErrorLoggedEventArgs e) {
// ...
}

For example:

void MMM_Logged(object sender, ErrorLoggedEventArgs e) {
Debug.WriteLine(string.Format("{0} = {1}",
e.Entry.Id, e.Entry.Error.Message));
}

The "MMM" in the name of the event handler above needs to be replaced with the name you gave to the module entry (under httpModules) in web.config. Say you named it ErrorLog, like this:

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

Then you'll need to name the event handler ErrorLog_Logged. This is the convention for handling events from any ASP.NET module (that is, configured module name + event name).

Hope this helps,
- Atif

Tony Bunce

unread,
Mar 23, 2009, 4:34:18 PM3/23/09
to el...@googlegroups.com
Thanks, That's exactly what I was looking for.

-Tony
Reply all
Reply to author
Forward
0 new messages