Reputation: 482
I am trying to Catch exceptions and log it.
Presently I have written a Utility method and Passing the Exception to it in the catch block and finally logging the application using MS Enterprise Library 4.0.
If someone can help me on this!
Navish
Upvotes: 2
Views: 1034
Reputation: 3217
Elmah
Elmah could be great option for you. It is easy to use, after installing nuget package is ready for use.
Custom logging with log4net etc.
If you want to log errors by your own, I recommend this example app: https://github.com/mholec/mvcexceptionhandler where is explained global logging with your favorite log tool (log4net, nlog, etc.)
Application Insights
Another and maybe the best way is to use Application Insights. Application Insights you can install quickly using NuGet and you will get great overview of your application errors, website availability and you can get more information about your users. This service is free.
Upvotes: 1
Reputation: 2063
I recommend ELMAH http://code.google.com/p/elmah/
You can get started very quickly with it by using Nuget to set it up. http://nuget.codeplex.com/
You can view the log just like trace.axd by going to http://mysite/elmah.axd and manually throw errors to elmah like this:
try {
}
catch (Exception ex)
{
ErrorSignal.FromCurrentContext().Raise(ex);
}
hope that helps, -fs
Upvotes: 0
Reputation: 63502
If you were rolling your own Exception logging you could create a base Controller class that overrides the OnException method
public class BaseController : Controller
{
protected override void OnException(ExceptionContext filterContext)
{
ExceptionPolicy.HandleException(filterContext.Exception, "MyPolicy");
base.OnException(filterContext);
}
}
Upvotes: 2