title: how to log request and response in asp.net webapi as a text file on daily basis?
body: <p>I need to log the requests and responses in a text file using asp.net webAPI. provide with good simple example. I heard about using delegate handler we can achieve it as below. </p>
  
  <pre><code>public class LogRequestAndResponseHandler : DelegatingHandler
  {
      protected override async Task&lt;HttpResponseMessage&gt; SendAsync(
          HttpRequestMessage request, CancellationToken cancellationToken)
      {
          //logging request body
          string requestBody = await request.Content.ReadAsStringAsync();
          Trace.WriteLine(requestBody);
  
          //let other handlers process the request
          return await base.SendAsync(request, cancellationToken)
              .ContinueWith(task =&gt;
                  {
                      //once response is ready, log it
                      var responseBody = task.Result.Content;
                      Trace.WriteLine (responseBody);
  
                      return task.Result;
                  });
      }
  }
  </code></pre>
  
  <p>but how to save request and response in a text file on daily basis. Provide with good simple example.</p>