Alex Rivera | Logout

Exception handling and logging strategy in .NET

Asked 2011-03-04T11:05:48.983
14

I am building a multi-layered application that has an ASP.NET MVC web application. It conists of the usuals like presentation layer, business layer, data layer, etc. How would one create/use a decent exception handling mechanism? I read on Patterns and Practices that you need to bubble up exceptions to the various layers.

Also logging. Where does logging take place? In the MVC web application?

How would you redirect to various error pages depending on the type of error?

I would appreciate some feedback regarding this, and some articles if you guys have some. If there are any sample apps that make use of a decent exception hadling and logging strategy please let me know :)

Edit
Report

1 Answer

6

In my MVC3 application I use ELMAH for the exception handling as described here How to get ELMAH to work with ASP.NET MVC [HandleError] attribute?, while if I need to log a custom message I use the Trace methods that comes from the System.Diagnostics, here a useful link Overriding System.Diagnostics.Trace.WriteLine to log to a file.

UPDATE Now you can set up elmah in your application directly with the NuGet packager. http://gregorsuttie.wordpress.com/2011/02/02/elmah-using-nuget-what-they-are-and-why-you-should-use-them-part-1/

answered 2011-03-04T11:18:42.460

Your Answer