views:

23

answers:

2

Hi

I'm newbie when talks about Error Handling. It's a subject that i want to study but right now i just don't have free time, so i'm looking to implement an error/exception handler one a few projects i've developing last weeks (C#, .NET 3.5).

What do you recommend me to implement for this? Other point is where to store the errors logs. In database or .xml file? Well, i really need some help on this!

By the way, is there any book about error handling?

Thanks in advanced, Guilherme Cardoso

A: 

Log4net is a robust tool for logging to a variety of sources. Where I work, we use the Logging Application Blocks from the Enterprise Library. You can read up about these resources on their websites.

As for logging to XML files vs. databases, there are tradeoffs to each approach. Using local files reduces how many breakable components are required for a functioning application. Imagine that the database goes down, and your app tries to log to the database that the database went down... Hmmm.

On the other hand, logging to a database can dramatically improve your ability to query and gain intelligence on the nature of errors that get logged.

No one will be able to tell you absolutely what you should do; just weigh the tradeoffs and your expectations, and you'll be good to go.

If you want to go with some home-brewed error handling, you can tap into the Application_Error method of your Global.asax and manually log members of the HttpContext.Current.AllErrors property. You can also use the ClearError() method on the context to wipe out the errors, and then redirect to a safe page if you want to log-and-continue.

Good luck!

kbrimington
A: 

For unhandled exceptions you might want to use ELMAH. Its super simple to setup - just a dll and some settings in your web.config.

geoff
Thanks mate. It was really simple to implement elmah, and i've just need to add an defaultRedirect in costumerrors and now it's done (for now!)Thanks ;)
Guilherme Cardoso
@Guilherme - no problem. I use it all the time in my projects.
geoff