-
-
Save Adolfi/8bd576f8e4fd688c8f0c2cd519ab45b5 to your computer and use it in GitHub Desktop.
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 LogHttpRequestDelegatingHandler : DelegatingHandler | |
{ | |
private readonly ILogger<LogHttpRequestDelegatingHandler> logger; | |
public LogHttpRequestDelegatingHandler(ILogger<LogHttpRequestDelegatingHandler> logger) | |
{ | |
this.logger = logger; | |
} | |
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | |
{ | |
var stopWatch = Stopwatch.StartNew(); | |
this.logger.LogInformation("Calling {HttpMethod} {RequestUri} at: {Now}", request.Method, request.RequestUri, DateTime.Now); | |
var response = await base.SendAsync(request, cancellationToken); | |
stopWatch.Stop(); | |
this.logger.LogInformation("Response: StatusCode: {StatusCode}. Executed in: {Elapsed}", response.StatusCode, stopWatch.Elapsed); | |
return response; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment