Asynchronous error handling in MVC 5 filters
<p>I've made a custom filter attribute extending the <code>HandleErrorAttribute</code>, that catches all exceptions.</p>

<p>My entire application is built around async architechture, throughout the stack.
This means, that I somehow have to use the <code>OnException(ExceptionContext contect)</code> override asynchronously. Something like this, would be how I imagined it (Simplified for readability):</p>

<pre><code>public async override void OnException(ExceptionContext context)
{
    base.OnException(context);
    var logId = await LogException(e, httpContext); //LogException calls an async method and returns the ID of the exception, after it has been saved to the database. I this ID in the filterContext, which is why I need the result of the method
}
</code></pre>

<p>However, this would result in <code>InvalidOperationException: An asynchronous operation cannot be started at this time. Asynchronous operations may only be started within an asynchronous handler or module or during certain events in the Page lifecycle</code>.</p>

<p>I cannot simply call .Result on the task when called synchronously, as this would cause deadlocks.</p>

<p>So I guess my question is: How do I create a filter in MVC5, that can log errors asynchronously?</p>