title: ASP.NET Web API IExceptionLogger doesn't catch exceptions
body: <p>I'm trying to setup a global exception handler as outlined here: <a href="http://www.asp.net/web-api/overview/web-api-routing-and-actions/web-api-global-error-handling">Web API Global Error Handling</a>. I"ve setup a case where an exception gets thrown within a controller constructor. But my exception isn't getting logged. Instead WebApi is just returning the exception and full stack trace to the calling client as a JSON message.</p>
  
  <p>I don't know if it matters, but my controllers actions are using async / await like this:</p>
  
  <pre><code>[HttpGet, Route("GetLocationNames")]
  public async Task&lt;IEnumerable&lt;String&gt;&gt; Get()
  {
      return await adapter.GetLocationNames();
  }
  </code></pre>
  
  <p>I have the following implementation:</p>
  
  <pre><code>using log4net;
  using System.Threading.Tasks;
  using System.Web.Http.ExceptionHandling;
  
  namespace warehouse.management.api
  {
      public class Log4NetExceptionLogger : ExceptionLogger
      {
          private ILog log = LogManager.GetLogger(typeof(Log4NetExceptionLogger));
  
          public async override Task LogAsync(ExceptionLoggerContext context, System.Threading.CancellationToken cancellationToken)
          {
              log.Error("An unhandled exception occurred.", context.Exception);
              await base.LogAsync(context, cancellationToken);
          }
  
          public override void Log(ExceptionLoggerContext context)
          {
              log.Error("An unhandled exception occurred.", context.Exception);
              base.Log(context);
          }
  
          public override bool ShouldLog(ExceptionLoggerContext context)
          {
              return base.ShouldLog(context);
          }
      }
  }
  </code></pre>
  
  <p>And I'm registering it like this:</p>
  
  <pre><code>using Owin;
  using System.Web.Http;
  using System.Web.Http.ExceptionHandling;
  
  namespace warehouse.management.api.Config
  {
      public static class WebApiConfig
      {
  
          public static IAppBuilder RegisterApiConfig(this IAppBuilder app, HttpConfiguration config)
          {
              config.MapHttpAttributeRoutes();
              config.Services.Add(typeof(IExceptionLogger), new Log4NetExceptionLogger());
              return app;
          }
      }
  }
  </code></pre>
  
  <p>And here's my packages.conf:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;packages&gt;
      &lt;package id="log4net" version="2.0.3" targetFramework="net45" /&gt;
      &lt;package id="Microsoft.AspNet.WebApi.Client" version="5.1.2" targetFramework="net45" /&gt;
      &lt;package id="Microsoft.AspNet.WebApi.Core" version="5.1.2" targetFramework="net45" /&gt;
      &lt;package id="Microsoft.AspNet.WebApi.Owin" version="5.1.2" targetFramework="net45" /&gt;
      &lt;package id="Microsoft.AspNet.WebApi.WebHost" version="4.0.20505.0" targetFramework="net45" /&gt;
      &lt;package id="Microsoft.Owin" version="2.1.0" targetFramework="net45" /&gt;
      &lt;package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" /&gt;
      &lt;package id="Newtonsoft.Json" version="4.5.11" targetFramework="net45" /&gt;
      &lt;package id="Owin" version="1.0" targetFramework="net45" /&gt;
      &lt;package id="Unity" version="3.5.1404.0" targetFramework="net45" /&gt;
      &lt;package id="Unity.AspNet.WebApi" version="3.5.1404.0" targetFramework="net45" /&gt;
      &lt;package id="WebActivatorEx" version="2.0" targetFramework="net45" /&gt;
  &lt;/packages&gt;
  </code></pre>