Where or when to log exceptions in an MVC 5 application
<p>I would like to follow lots of advice to just use a global <code>HandleErrorAttribute</code>, but this attribute seems to go straight to displaying the <code>Error</code> view, leaving me no place to log the exception. I don't believe the view is the right place for logging and other business logic.</p>

<p>I also have the option of overriding <code>OnException</code> in my <code>BaseController</code>, but am worried about a conflict with <code>HandleErrorAttribute</code>. If I override <code>OnException</code> as follows, leaving the exception unhandled, will it carry on through to <code>HandleErrorAttribute</code>?</p>

<pre><code>protected override void OnException(ExceptionContext filterContext)
{
    Exception exception = filterContext.Exception;
    var controller = filterContext.RouteData.Values["controller"].ToString();
    var action = filterContext.RouteData.Values["action"].ToString();
    logger.Error(exception, "Exception in controller '{0}': action '{1}'.", controller, action);
    filterContext.Exception = exception;
    //filterContext.ExceptionHandled = true;
}
</code></pre>

<p>Or how else do I go about logging the exception? I believe the above two methods save me from implementing a 'try-catch' on every action method, and with catching specific exceptions this could be quite some chore. I would also like to have the option to restart the application or something should a really catastrophic exception occur, and again <code>HandleErrorAttribute</code> doesn't leave much room for that.</p>