diff options
author | Wouter Tinus <wouter.tinus@gmail.com> | 2020-05-13 19:22:03 +0200 |
---|---|---|
committer | Wouter Tinus <wouter.tinus@gmail.com> | 2020-05-13 19:22:03 +0200 |
commit | 514e903e87ce0e5bf2d791394e324f3d164f4a5c (patch) | |
tree | d19299cc033d82ac16990995fa0db237760c852f /src | |
parent | 25d0a23aee4c16fa1db07625cad560bf5453df72 (diff) | |
download | letsencrypt-win-simple-514e903e87ce0e5bf2d791394e324f3d164f4a5c.zip letsencrypt-win-simple-514e903e87ce0e5bf2d791394e324f3d164f4a5c.tar.gz letsencrypt-win-simple-514e903e87ce0e5bf2d791394e324f3d164f4a5c.tar.bz2 |
Log all requests going through our HttpClient instead of only those that AcmeSharpCore triggers events on
Diffstat (limited to 'src')
-rw-r--r-- | src/main.lib/Clients/Acme/AcmeClient.cs | 2 | ||||
-rw-r--r-- | src/main.lib/Services/ProxyService.cs | 19 |
2 files changed, 18 insertions, 3 deletions
diff --git a/src/main.lib/Clients/Acme/AcmeClient.cs b/src/main.lib/Clients/Acme/AcmeClient.cs index 1c969b2..ea7b380 100644 --- a/src/main.lib/Clients/Acme/AcmeClient.cs +++ b/src/main.lib/Clients/Acme/AcmeClient.cs @@ -134,8 +134,6 @@ namespace PKISharp.WACS.Clients.Acme throw; } } - client.BeforeHttpSend = (x, r) => _log.Debug("Send {method} request to {uri}", r.Method, r.RequestUri); - client.AfterHttpSend = (x, r) => _log.Verbose("Request completed with status {s}", r.StatusCode); return client; } diff --git a/src/main.lib/Services/ProxyService.cs b/src/main.lib/Services/ProxyService.cs index f2d49a9..9287ed1 100644 --- a/src/main.lib/Services/ProxyService.cs +++ b/src/main.lib/Services/ProxyService.cs @@ -2,6 +2,8 @@ using System.Net; using System.Net.Http; using System.Security.Authentication; +using System.Threading; +using System.Threading.Tasks; namespace PKISharp.WACS.Services { @@ -29,7 +31,7 @@ namespace PKISharp.WACS.Services /// <returns></returns> public HttpClient GetHttpClient(bool checkSsl = true) { - var httpClientHandler = new HttpClientHandler() + var httpClientHandler = new LoggingHttpClientHandler(_log) { Proxy = GetWebProxy(), SslProtocols = SslProtocols @@ -45,6 +47,21 @@ namespace PKISharp.WACS.Services return new HttpClient(httpClientHandler); } + private class LoggingHttpClientHandler : HttpClientHandler + { + private readonly ILogService _log; + + public LoggingHttpClientHandler(ILogService log) => _log = log; + + protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { + _log.Debug("Send {method} request to {uri}", request.Method, request.RequestUri); + var response = await base.SendAsync(request, cancellationToken); + _log.Verbose("Request completed with status {s}", response.StatusCode); + return response; + } + } + + /// <summary> /// Get proxy server to use for web requests /// </summary> |