1

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?

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

I second this as the best option!
1

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.

1 Comment

Thanks, this helped me out. I had to do some more research to see what should go into the MvcApplication_Error method. It's good to know you can do a Response.Redirect to your error page from there. Response.Redirect("~/Shared.mvc/Error");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.