I would like to implement exception handling on a ASP.NET application. How do you suggest I implement it? Some requirements are:
- User should see a friendly page when an exception occurs
- Admin should get an email with exception details
I understand there are several ways of implementing exceptions (ex: Log messages in the event viewer)
What’s the recommended approach?
The recommended approach really depends on what you need to do with the error information.
For simple apps, just setting up the web.config file to redirect to a friendly error page might be enough.
It’s usually a good idea to record unhandled error information to a database, file, windows application log or web service by handling them with the Global.asax
Application_Errorevent. You can also use the web.config to get your friendly page with that. Generally I wouldn’t recommend using the windows error logs as they tend to be a bit obtuse, but there’s nothing wrong with it.For very detailed operational information, including warnings and info messages, tools like log4net are widely used. Usually you would go this route for products or enterprise level applications where your support teams need as much information as possible to diagnose the errors.
MSDN has a walkthrough of some of the basic error handling setups and what you can do with them.