![]() |
VOOZH | about |
dotnet add package Microsoft.Extensions.Http.Diagnostics --version 10.7.0
NuGet\Install-Package Microsoft.Extensions.Http.Diagnostics -Version 10.7.0
<PackageReference Include="Microsoft.Extensions.Http.Diagnostics" Version="10.7.0" />
<PackageVersion Include="Microsoft.Extensions.Http.Diagnostics" Version="10.7.0" />Directory.Packages.props
<PackageReference Include="Microsoft.Extensions.Http.Diagnostics" />Project file
paket add Microsoft.Extensions.Http.Diagnostics --version 10.7.0
#r "nuget: Microsoft.Extensions.Http.Diagnostics, 10.7.0"
#:package Microsoft.Extensions.Http.Diagnostics@10.7.0
#addin nuget:?package=Microsoft.Extensions.Http.Diagnostics&version=10.7.0Install as a Cake Addin
#tool nuget:?package=Microsoft.Extensions.Http.Diagnostics&version=10.7.0Install as a Cake Tool
Telemetry support for HttpClient that allows tracking latency and enriching and redacting log output for structured logs.
From the command-line:
dotnet add package Microsoft.Extensions.Http.Diagnostics
Or directly in the C# project file:
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http.Diagnostics" Version="[CURRENTVERSION]" />
</ItemGroup>
These components enable enriching and redacting HttpClient request logs. They remove built-it HTTP Client logging.
When using this package, some of the log properties are redacted by default (like full routes), which means that you will need to make sure that a redactor provider is registered in the Dependency Injection container. You can do this by making sure that you call builder.Services.AddRedaction() which requires a reference to the Microsoft.Extensions.Compliance.Redaction package.
The http client logging services can be registered using the following methods:
public static IServiceCollection AddExtendedHttpClientLogging(this IServiceCollection services)
public static IServiceCollection AddExtendedHttpClientLogging(this IServiceCollection services, IConfigurationSection section)
public static IServiceCollection AddExtendedHttpClientLogging(this IServiceCollection services, Action<LoggingOptions> configure)
public static IServiceCollection AddHttpClientLogEnricher<T>(this IServiceCollection services) where T : class, IHttpClientLogEnricher
For example:
var builder = Host.CreateApplicationBuilder(args);
// Register IHttpClientFactory:
builder.Services.AddHttpClient();
// Register redaction services:
builder.Services.AddRedaction();
// Register HttpClient logging enrichment & redaction services:
builder.Services.AddExtendedHttpClientLogging();
// Register a logging enricher (the type should implement IHttpClientLogEnricher):
builder.Services.AddHttpClientLogEnricher<MyHttpClientLogEnricher>();
var host = builder.Build();
It is important to note that the AddExtendedHttpClientLogging method will add information to the logs using enrichment. This means that the information will be added as tags to the structured logs, but will not be visible in the log message that is printed by default in the console. To view the information, you will need to use a logging provider that supports structured logs. One quick and built-in way to do this, is to call AddJsonConsole() to your logging builder, which will print out the full structured logs to the console. Here is a quick sample that uses the ExtendedHttpClientLogging() method to automatically log all HttpClient request and response bodies, and then prints the full structured logs to the console:
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
var services = new ServiceCollection();
services.AddLogging(o => o.SetMinimumLevel(LogLevel.Trace).AddJsonConsole()); // <-- Enable structured logging to the console
// Adding default redactor provider to the DI container. This is required when using the AddExtendedHttpClientLogging() method.
services.AddRedaction();
services.AddHttpClient("foo")
.AddExtendedHttpClientLogging(o =>
{
// Enable logging of request and response bodies:
o.LogBody = true;
// We also need to specify the content types that we want to log:
o.ResponseBodyContentTypes.Add("application/json");
});
var sp = services.BuildServiceProvider();
var client = sp.GetRequiredService<IHttpClientFactory>().CreateClient("foo");
var response = await client.GetAsync(new Uri("https://httpbin.org/json")).ConfigureAwait(false);
By default, request and response routes are redacted for privacy reasons. You can change this behavior by making use of the RequestPathParameterRedactionMode option like:
.AddExtendedHttpClientLogging(o =>
{
//.. Other options
o.RequestPathParameterRedactionMode = HttpRouteParameterRedactionMode.None; // <-- Disable redaction of request/response routes
});
You can also use the following extension methods to apply the logging to the specific IHttpClientBuilder:
public static IHttpClientBuilder AddExtendedHttpClientLogging(this IHttpClientBuilder builder)
public static IHttpClientBuilder AddExtendedHttpClientLogging(this IHttpClientBuilder builder, IConfigurationSection section)
public static IHttpClientBuilder AddExtendedHttpClientLogging(this IHttpClientBuilder builder, Action<LoggingOptions> configure)
For example:
var builder = Host.CreateApplicationBuilder(args);
// Register redaction services:
builder.Services.AddRedaction();
// Register named HttpClient:
var httpClientBuilder = builder.Services.AddHttpClient("MyNamedClient");
// Configure named HttpClient to use logging enrichment & redaction:
httpClientBuilder.AddExtendedHttpClientLogging();
var host = builder.Build();
These components enable tracking and reporting the latency of HTTP Client request processing.
The services can be registered using the following methods:
public static IServiceCollection AddHttpClientLatencyTelemetry(this IServiceCollection services)
public static IServiceCollection AddHttpClientLatencyTelemetry(this IServiceCollection services, IConfigurationSection section)
public static IServiceCollection AddHttpClientLatencyTelemetry(this IServiceCollection services, Action<HttpClientLatencyTelemetryOptions> configure)
For example:
var builder = Host.CreateApplicationBuilder(args);
// Register IHttpClientFactory:
builder.Services.AddHttpClient();
// Register redaction services:
builder.Services.AddRedaction();
// Register latency context services:
builder.Services.AddLatencyContext();
// Register HttpClient logging enrichment & redaction services:
builder.Services.AddExtendedHttpClientLogging();
// Register HttpClient latency telemetry services:
builder.Services.AddHttpClientLatencyTelemetry();
var host = builder.Build();
We welcome feedback and contributions in our GitHub repo.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 is compatible. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 2 NuGet packages that depend on Microsoft.Extensions.Http.Diagnostics:
| Package | Downloads |
|---|---|
|
Microsoft.Extensions.Http.Resilience
Resilience mechanisms for HttpClient. |
|
|
Puntual.AI.OpenAI
Librer�a de OpenAI de Puntual. |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 10.7.0 | 321,100 | 6/9/2026 |
| 10.6.0 | 2,209,652 | 5/12/2026 |
| 10.5.0 | 3,649,168 | 4/15/2026 |
| 10.4.0 | 3,568,696 | 3/10/2026 |
| 10.3.0 | 3,864,192 | 2/10/2026 |
| 10.2.0 | 3,964,696 | 1/13/2026 |
| 10.1.0 | 4,649,216 | 12/9/2025 |
| 10.0.0 | 7,251,347 | 11/11/2025 |
| 9.10.0 | 5,258,869 | 10/14/2025 |
| 9.9.0 | 5,009,706 | 9/9/2025 |
| 9.8.0 | 2,433,612 | 8/12/2025 |
| 9.7.0 | 3,977,784 | 7/8/2025 |
| 9.6.0 | 3,320,036 | 6/10/2025 |
| 9.5.0 | 3,020,575 | 5/13/2025 |
| 9.4.0 | 4,010,611 | 4/8/2025 |
| 9.3.0 | 2,354,723 | 3/11/2025 |
| 9.2.0 | 3,969,710 | 2/11/2025 |
| 9.1.0 | 2,600,471 | 1/14/2025 |
| 9.0.0 | 7,126,949 | 11/12/2024 |
| 8.10.0 | 13,538,075 | 10/8/2024 |