Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Logging all unhandled ASP.NET C# exceptions

Posted on 2008-06-18
2
Medium Priority
?
800 Views
Last Modified: 2011-10-03
This is probably quite easy; does anyone know how I can log all unhandled exceptions on my ASP.NET application to a database? Ie, for any unhandled exception, call LogException(Exception e) and then divert user to a page which says "The website has encountered an error - the administrator has been notified".

ASP.NET, C#
0
Comment
Question by:jimstar
2 Comments
 
LVL 16

Accepted Solution

by:
ororiole earned 2000 total points
ID: 21818575
Yes indeed. The framework has just such a feature. To your solution right click and add a new item. Add a global.asax file. (I think the dialog calls it a global class file or something). In there you will see an
Applicaiton_Error event handler. Modify it like so, assumeing you have a LogException function:
        protected void Application_Error(object sender, EventArgs e)
        {
            LogException(Server.GetLastError());
            Server.ClearError();
            Server.Transfer("Default2.aspx");
 
        }

Open in new window

0
 
LVL 4

Author Closing Comment

by:jimstar
ID: 31468643
Fantastic, thanks!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Screencast - Getting to Know the Pipeline
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

879 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question