title: How to auto log every request in .NET Core WebAPI?
body: <p>I'd like to have every request logged automatically. In previous .Net Framwork WebAPI project, I used to register a delegateHandler to do so.</p>
  
  <p>WebApiConfig.cs</p>
  
  <pre><code>public static void Register(HttpConfiguration config)
  {
      config.MessageHandlers.Add(new AutoLogDelegateHandler());
  }
  </code></pre>
  
  <p>AutoLogDelegateHandler.cs</p>
  
  <pre><code>public class AutoLogDelegateHandler : DelegatingHandler
  {
  
      protected override async Task&lt;HttpResponseMessage&gt; SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
      {
          var requestBody = request.Content.ReadAsStringAsync().Result;
  
          return await base.SendAsync(request, cancellationToken)
              .ContinueWith(task =&gt;
              {
                  HttpResponseMessage response = task.Result;
  
                  //Log use log4net
                  _LogHandle(request, requestBody, response);
  
                  return response;
              });
      }
  }
  </code></pre>
  
  <p>an example of the log content:</p>
  
  <pre><code>------------------------------------------------------
  2017-08-02 19:34:58,840
  uri: /emp/register
  body: {
      "timeStamp": 1481013427,
      "id": "0322654451",
      "type": "t3",
      "remark": "system auto reg"
  }
  response: {"msg":"c556f652fc52f94af081a130dc627433","success":"true"}
  ------------------------------------------------------
  </code></pre>
  
  <p>But in .NET Core WebAPI project, there is no <code>WebApiConfig</code> , or the register function at Global.asax <code>GlobalConfiguration.Configure(WebApiConfig.Register);</code></p>
  
  <p>So is there any way to achieve that in .NET Core WebAPI?</p>