Alyio.Extensions.Http.Logging 3.0.0

dotnet add package Alyio.Extensions.Http.Logging --version 3.0.0                
NuGet\Install-Package Alyio.Extensions.Http.Logging -Version 3.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Alyio.Extensions.Http.Logging" Version="3.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Alyio.Extensions.Http.Logging --version 3.0.0                
#r "nuget: Alyio.Extensions.Http.Logging, 3.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Alyio.Extensions.Http.Logging as a Cake Addin
#addin nuget:?package=Alyio.Extensions.Http.Logging&version=3.0.0

// Install Alyio.Extensions.Http.Logging as a Cake Tool
#tool nuget:?package=Alyio.Extensions.Http.Logging&version=3.0.0                

Alyio.Extensions.Http.Logging

Build Status

Alyio..Extensions.Http.Logging extends the HttpClientHandler for logging the HTTP request message and the HTTP response message.

To use the HttpClientHandler, please use IHttpClientBuilder.AddLoggerHandler to add LoggerHandler as an handler into a specified HttpClient.

For example, the follow is a sample logging section.

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

var host = Host.CreateDefaultBuilder()
    .ConfigureServices((context, services) =>
    {
        services.AddHttpClient<IOpenWeatherMapService, OpenWeatherMapService>(
            configureClient => configureClient.BaseAddress = new Uri("http://samples.openweathermap.org"))
            .AddLoggerHandler(ignoreRequestContent: false, ignoreResponseContent: false);

        services.AddHostedService<OpenWeatherMapHostedService>();
    })
    .ConfigureLogging(logging =>
    {
        logging.SetMinimumLevel(LogLevel.Warning);
        logging.AddFilter("System.Net.Http.HttpClient.IOpenWeatherMapService.LoggingHandler", LogLevel.Information);
    })
    .UseConsoleLifetime();

await host.RunConsoleAsync();


sealed class OpenWeatherMapHostedService : IHostedService
{
    private readonly IOpenWeatherMapService _openWeatherMap;

    public OpenWeatherMapHostedService(IOpenWeatherMapService weatherMapService)
    {
        _openWeatherMap = weatherMapService;
    }

    public Task StartAsync(CancellationToken cancellationToken)
    {
        return _openWeatherMap.GetAsync();
    }

    public Task StopAsync(CancellationToken cancellationToken)
    {
        return Task.CompletedTask;
    }
}

internal interface IOpenWeatherMapService
{
    Task GetAsync();
}

sealed class OpenWeatherMapService : IOpenWeatherMapService
{
    private readonly HttpClient _client;

    public OpenWeatherMapService(HttpClient client)
    {
        _client = client;
    }

    public Task GetAsync()
    {
        return _client.GetAsync("/data/2.5/weather?q=London,uk&appid=b1b15e88fa797225412429c1c50c122a1");
    }
}
$ dotnet run
info: System.Net.Http.HttpClient.IOpenWeatherMapService.LoggerHandler[0]
      Request-Queue: 1
info: System.Net.Http.HttpClient.IOpenWeatherMapService.LoggerHandler[0]
      Request-Message: 
      
      GET http://samples.openweathermap.org/data/2.5/weather?q=London,uk&appid=b1b15e88fa797225412429c1c50c122a1 HTTP/1.1
      
info: System.Net.Http.HttpClient.IOpenWeatherMapService.LoggerHandler[0]
      Response-Message: 4732ms
      
      HTTP/1.1 200 OK
      Server: openresty/1.9.7.1
      Date: Thu, 02 Jun 2022 15:42:01 GMT
      Transfer-Encoding: chunked
      Connection: keep-alive
      X-Frame-Options: SAMEORIGIN
      X-XSS-Protection: 1; mode=block
      X-Content-Type-Options: nosniff
      ETag: W/"e70c27085ed41de5321252b16c9582fe"
      Cache-Control: must-revalidate, max-age=0, private
      X-Request-ID: ab78dbeb-90bb-49d9-8812-984205851f0f
      X-Runtime: 0.001029
      Content-Type: application/json; charset=utf-8
      
      {"coord":{"lon":-0.13,"lat":51.51},"weather":[{"id":300,"main":"Drizzle","description":"light intensity drizzle","icon":"09d"}],"base":"stations","main":{"temp":280.32,"pressure":1012,"humidity":81,"temp_min":279.15,"temp_max":281.15},"visibility":10000,"wind":{"speed":4.1,"deg":80},"clouds":{"all":90},"dt":1485789600,"sys":{"type":1,"id":5091,"message":0.0103,"country":"GB","sunrise":1485762037,"sunset":1485794875},"id":2643743,"name":"London","cod":200}
^C
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.0 241 6/6/2023
2.0.1 444 7/12/2022