Created
May 27, 2014 19:41
-
-
Save ebaxt/68f2107216fe1dec56a0 to your computer and use it in GitHub Desktop.
LoggingHandler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LoggingHandler : DelegatingHandler | |
{ | |
public LoggingHandler(HttpMessageHandler innerHandler) | |
: base(innerHandler) | |
{ | |
} | |
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | |
{ | |
Debug.WriteLine("Request:"); | |
Debug.WriteLine(request.ToString()); | |
if (request.Content != null) | |
{ | |
Debug.WriteLine(await request.Content.ReadAsStringAsync()); | |
} | |
Debug.WriteLine(""); | |
HttpResponseMessage response = await base.SendAsync(request, cancellationToken); | |
Debug.WriteLine("Response:"); | |
Debug.WriteLine(response.ToString()); | |
if (response.Content != null) | |
{ | |
Debug.WriteLine(await response.Content.ReadAsStringAsync()); | |
} | |
Debug.WriteLine(""); | |
return response; | |
} | |
} | |
;; Usage | |
var client = new HttpClient(new LoggingHandler(new HttpClientHandler())); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment