views:

22

answers:

2

I am logging errors in my controllers method:

 protected override void OnException(ExceptionContext filterContext)

But if I make a type in my view page, or enter a route that doesn't exist, it doesn't seem to log that erorr?

+1  A: 

Use Elmah logging for that. No code required, just configuration. Elmah logs errors automatically in memory, xml, or a database, and provides a very nice userinterface for reviewing the errors.

See Scott Hanselman's explanation, and the official documentation, Using Elmah with ASP.NET MVC

Jan Willem B
I second this as the best option!
Mike Glenn
A: 

Thats because its a pipeline and you want to log at a different scope, to log this error add the following to your global.asax:

public override void Init()
{
    base.Error+=new EventHandler(MvcApplication_Error);
    base.Init();
}

The pipeline is basically this:

  1. incomming request
  2. Hits IIS/ ASP.net
  3. then the routing engine
  4. then the controllers
  5. then the views

so you need to get your error handlers in place before routing takes place to catch them.

AJ