views:

513

answers:

3

I have a another ASP.Net web project that I am working and I have approached error handling from different angles. I was just wondering if any seasoned and experienced developers out there had any recommendations.

Bonus points for discussions on a nice logging framework for ASP.net:)

A: 

It depends on the environment for which your application is targeted. But what I do is have a generic ErrorHandler.aspx page that I redirect to in the customErrors section of the web.config, and then any exception that I don't handle and hide causes the page to redirect to the error handler which lets the user know what happened and gives them the option to report it.

I would suggest deriving from System.Exception to make something that allows you to specify more specifics for the ErrorHandler.aspx page such as a FriendlyMessage property.

Max Schmeling
So would you redirect to an error page and pass through the friendly error message either through the URL or in the session and maybe call to the global error handling to send an email to the webmasters and the developers?
uriDium
You add a global application class (Global.asax - look in the Add Item window, you'll see it) and then in the Application_UnhandledError (something like that) you save Server.GetLastError() to some static property somewhere (I have a ErrorUtil class that has a static exception property)
Max Schmeling
then you access that property from ErrorHandler.aspx. In extremely high load applications thig might causes problems (overwritten before error page is generated, but I'm not sure about that) I don't have to worry about it where I work though
Max Schmeling
A: 

I use the Application_Error() event to grab unhandled exceptions. I write them to a log using the Application.Log() method, then I redirect them to a user-friendly error page.

The Application.Log() can be configured using the web.config file to direct the output to a file, the event log on the server, etc.

In some circumstances, I have also implemented my own logging using a generic TraceSource and custom Listener that logged the messages to a database table.

NYSystemsAnalyst
+2  A: 

I've used the ELMAH, (Error Logging Modules and Handlers) is an application-wide error logging facility that is completely pluggable, on several projects and it works great: http://code.google.com/p/elmah/

I've also used the built in Health Monitoring in ASP.NET 2.0: http://msdn.microsoft.com/en-us/library/ms998306.aspx

Nathan Prather