Catch Your Application Errors

by Vishwa 10. January 2008 16:51

You must be thinking that your web site is working great and generating no errors. But have you ever tried catching errors on Application_Error event in Global.asax, it catches all unhandled errors. Try applying the following code, and you will be amazed to see that your site is generating some errors which you were not even aware of. The following method will dump all the erros into a XML file which will be create on monthly basis. Initially I was sending these errors to my email, but it is not easy to analyze all the data at once. XML file can be imported in Excel easily and you can fix the code which is generating more errors.

Drop the following lines of code in your global.asax file - Make sure you choose one format, otherwise you will logging errors twice.

 Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)

        Dim exc As Exception = Web.HttpContext.Current.Server.GetLastError()

        If TypeOf exc Is Web.HttpUnhandledException Or exc.InnerException IsNot Nothing Then exc = exc.InnerException

 

        If exc IsNot Nothing Then

            'Attribute Format - Small File Size - less readability

            Call LogErrorAsXMLFileAttribute(exc, Request.ServerVariables("SERVER_NAME"), Request.ServerVariables("REMOTE_ADDR"), Request.ServerVariables("HTTP_REFERER"))

 

            'Element Format  - Large File Size - more readability

            'Call LogErrorAsXMLFileElement(exc, Request.ServerVariables("SERVER_NAME"), Request.ServerVariables("REMOTE_ADDR"), Request.ServerVariables("HTTP_REFERER"))

        End If 

End Sub

 

The Subroutines LogErrorAsXMLFileAttribute and LogErrorAsXMLFileElement are available on my previous post.

Tags:

.NET

Comments (3) -

search engine optimisation training
search engine optimisation training United States
7/23/2009 5:21:00 AM #

good stuff, thanks for sharing

Voguishchic
Voguishchic United States
7/30/2009 4:56:57 AM #

Great post!  Keep up the good work!

Lyn Penge
Lyn Penge Denmark
8/19/2009 1:53:38 AM #

Thanks.. Funny, I actually had this on my mind a few days ago..

Comments are closed

About Me

Me Hello,my name is
Vishwa Mohan Kumar, PMP
MCP SOA Certified Architect
I am a Software Architect. This blog is result of my experiments.

Flickr Photos

Calendar

<<  February 2012  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
2728291234
567891011

View posts in large calendar

Archive

Recent Comments

Comment RSS

Live Traffic Feed