Hi,
I am looking for a simple way to log exceptions to the database in my ASP.NET MVC application. I have looked at the “Exception Management Application Block” but I can´t find any simple and clear articels about how to handle this in ASP.NET MVC?
Maby I should just catch the exception as far up as possible and then log it to database but Im not sure how to do that in ASP.NET MVC. In WindowsForms there is diffrent events(like unexpectedException) to listen to where I can log, is there anything like that in ASP.NET MVC?
BestRegards
Edit1: I found a tool called elmah http://code.google.com/p/elmah/ but im not sure if this is a good solution and if it works well with ASP.NET MVC.
Then I also found this article http://www.davidjuth.com/asp-net-mvc-error-handler.aspx that looks easy and clear but I also do not know if this is the right way to go?
Use ELMAH, it is available on NuGet. It will log unhandled exceptions in a web app and provide an interface to view them. It can log to a variety of storage mechanisms including xml and sql databases, it can also email you errors. It is basically the solution for logging exceptions in ASP.Net applications (both WebForms and MVC).
If you are using ELMAH in an MVC app, there are some integration points that should be addressed. These can be handled pretty well in one shot by installing the ELMAH.Mvc package from NuGet.