title: ASP.NET Web Api 2 - Log every incoming request for specific actions
body: <p>I am working with ASP.NET Web Api 2. I have written two <code>Filter Attributes</code> which check every incoming request for specific headers and if the header keys are not present they return Unauthorized response to users.</p>
  
  <p>This is what I am doing (one of the filters):</p>
  
  <pre><code>public class HeaderFilterAttribute : AuthorizationFilterAttribute
      {
          public override void OnAuthorization(HttpActionContext actionContext)
          {
              var req = actionContext.Request;
  
  
              if (! req.Headers.Contains("api-key") || req.Headers.GetValues("api-key") == null)
              {
                  actionContext.Response = req.CreateResponse(HttpStatusCode.Unauthorized);
                  actionContext.Response.Content = new StringContent("Token required", Encoding.UTF8, "text/html");
              }
          }
  }
  </code></pre>
  
  <p>Now If the request contains valid header keys and they have reached the correct action method or endpoint, I want to log certain details about the request. </p>
  
  <p><strong>What is the right way to create a filter attribute for this scenario? Which method this filter attribute will override? Or can I achieve the desired result without creating a filter attribute.</strong>   I think it will not make sense to override <code>OnAuthorization()</code></p>