mirror of
https://github.com/AlexMacocian/WpfExtended.git
synced 2026-07-15 14:59:30 +00:00
26 lines
922 B
C#
26 lines
922 B
C#
using Microsoft.Extensions.Logging;
|
|
using System.Extensions;
|
|
using System.Net.Http;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace WpfExtended.Tests.Http
|
|
{
|
|
public class HttpMessageLogger : DelegatingHandler
|
|
{
|
|
private readonly ILogger logger;
|
|
public HttpMessageLogger(ILogger logger, HttpMessageHandler innerHandler) : base(innerHandler)
|
|
{
|
|
this.logger = logger.ThrowIfNull(nameof(logger));
|
|
}
|
|
|
|
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
|
{
|
|
this.logger.LogInformation($"{request.Method} - {request.RequestUri}");
|
|
var response = await base.SendAsync(request, cancellationToken);
|
|
this.logger.LogInformation($"{response.RequestMessage.RequestUri} - {response.StatusCode}");
|
|
return response;
|
|
}
|
|
}
|
|
}
|