title: WebAPI Global Exception Handling
body: <p>I have a ASP WebAPI project. I'm trying to setup a global exception handler on my basecontroller. So I created an <code>ExceptionFilterAttribute</code> like so.</p>
  
  <pre><code>using System.Web.Http.Filters;
  
  public class MyExceptionFilterAttribute : ExceptionFilterAttribute
  {
      protected static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  
      public override void OnException(HttpActionExecutedContext actionExecutedContext)
      {
          var exception = actionExecutedContext.Exception;
          log.Fatal(exception);
  
          base.OnException(actionExecutedContext);
      }
  }
  </code></pre>
  
  <p>Then I also registered it in <code>/App_Start/WebApiConfig.cs</code></p>
  
  <pre><code>public static class WebApiConfig
  {
      public static void Register(HttpConfiguration config)
      {
          // ...
  
          // Setup Filters
          config.Filters.Add(new MyExceptionFilterAttribute());
      }
  }
  </code></pre>
  
  <p>When I add the attributes to my controller (or base-controller), nothing gets logged. What am I doing wrong?</p>
  
  <p><strong>Edit: My controller throwing the exception:</strong></p>
  
  <pre><code>[HttpGet]
  public string Hello(string name)
  {
      if (name.Equals("error", StringComparison.OrdinalIgnoreCase))
      {
          throw new HttpResponseException(HttpStatusCode.InternalServerError);
      }
      else
      {
          return name;
      }
  }
  </code></pre>