![]() |
VOOZH | about |
dotnet add package Microsoft.Extensions.Telemetry --version 10.7.0
NuGet\Install-Package Microsoft.Extensions.Telemetry -Version 10.7.0
<PackageReference Include="Microsoft.Extensions.Telemetry" Version="10.7.0" />
<PackageVersion Include="Microsoft.Extensions.Telemetry" Version="10.7.0" />Directory.Packages.props
<PackageReference Include="Microsoft.Extensions.Telemetry" />Project file
paket add Microsoft.Extensions.Telemetry --version 10.7.0
#r "nuget: Microsoft.Extensions.Telemetry, 10.7.0"
#:package Microsoft.Extensions.Telemetry@10.7.0
#addin nuget:?package=Microsoft.Extensions.Telemetry&version=10.7.0Install as a Cake Addin
#tool nuget:?package=Microsoft.Extensions.Telemetry&version=10.7.0Install as a Cake Tool
This library provides advanced logging and telemetry enrichment capabilities for .NET applications. It allows for detailed and configurable enrichment of log entries, along with enhanced latency monitoring and logging features. It is built for applications needing sophisticated telemetry and logging insights.
From the command-line:
dotnet add package Microsoft.Extensions.Telemetry
Or directly in the C# project file:
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Telemetry" Version="[CURRENTVERSION]" />
</ItemGroup>
The library provides two types of log sampling mechanisms: Random Probabilistic Sampling and Trace-based Sampling.
Provides configurable probability-based sampling with flexible rules:
// Simple configuration with probability
builder.Logging.AddRandomProbabilisticSampler(0.1); // Sample 10% of all logs, meaning - 90% of logs will be dropped
builder.Logging.AddRandomProbabilisticSampler(0.1, LogLevel.Warning); // Sample 10% of Warning and lower level logs
// Configuration using options
builder.Logging.AddRandomProbabilisticSampler(options =>
{
options.Rules.Add(new RandomProbabilisticSamplerFilterRule(0.1, logLevel: LogLevel.Information)); // Sample 10% of Information and lower level logs
options.Rules.Add(new RandomProbabilisticSamplerFilterRule(1.0, logLevel: LogLevel.Error)); // Sample all Error logs
});
// Configuration using IConfiguration
builder.Logging.AddRandomProbabilisticSampler(configuration.GetSection("Logging:Sampling"));
The Random Probabilistic Sampler supports the IOptionsMonitor<T> pattern, allowing for dynamic configuration updates. This means you can change the sampling rules at runtime without needing to restart your application.
Matches logging sampling decisions with the underlying Distributed Tracing sampling decisions:
// Add trace-based sampler
builder.Logging.AddTraceBasedSampler();
This comes in handy when you already use OpenTelemetry .NET Tracing and would like to see sampling decisions being consistent across both logs and their underlying Activity.
Provides a buffering mechanism for logs, allowing you to store logs in temporary circular buffers in memory. If the buffer is full, the oldest logs will be dropped. If you want to emit the buffered logs, you can call Flush() on the buffer. That way, if you don't flush buffers, all buffered logs will eventually be dropped and that makes sense - if you don't flush buffers, chances are
those logs are not important. At the same time, you can trigger a flush on the buffer when certain conditions are met, such as when an exception occurs.
This library works with all logger providers, even if they do not implement the Microsoft.Extensions.Logging.Abstractions.IBufferedLogger interface. In that case, the library will
be calling ILogger.Log() method directly on every single buffered log record when flushing the buffer.
Provides application-wide log buffering with configurable rules:
// Simple configuration with log level
builder.Logging.AddGlobalBuffer(LogLevel.Warning); // Buffer Warning and lower level logs
// Configuration using options
builder.Logging.AddGlobalBuffer(options =>
{
options.Rules.Add(new LogBufferingFilterRule(logLevel: LogLevel.Information)); // Buffer Information and lower level logs
options.Rules.Add(new LogBufferingFilterRule(categoryName: "Microsoft.*")); // Buffer logs from Microsoft namespaces
});
// Configuration using IConfiguration
builder.Logging.AddGlobalBuffer(configuration.GetSection("Logging:Buffering"));
Then, to flush the global buffer when a bad thing happens, call the Flush() method on the injected GlobalLogBuffer instance:
public class MyService
{
private readonly GlobalLogBuffer _globalLogBuffer;
public MyService(GlobalLogBuffer globalLogBuffer)
{
_globalLogBuffer = globalLogBuffer;
}
public void DoSomething()
{
try
{
// ...
}
catch (Exception ex)
{
// Flush the global buffer when an exception occurs
_globalLogBuffer.Flush();
}
}
}
The Global Log Buffer supports the IOptionsMonitor<T> pattern, allowing for dynamic configuration updates. This means you can change the buffering rules at runtime without needing to restart your application.
ILogger.BeginScope() method, the buffered log records will not be associated with the scope.Microsoft.Extensions.Logging.Abstractions.BufferedLogRecord class when converting buffered log records to actual log records, but omits following properties:Microsoft.Extensions.Logging.Abstractions.BufferedLogRecord.ActivitySpanIdMicrosoft.Extensions.Logging.Abstractions.BufferedLogRecord.ActivityTraceIdMicrosoft.Extensions.Logging.Abstractions.BufferedLogRecord.ManagedThreadIdMicrosoft.Extensions.Logging.Abstractions.BufferedLogRecord.MessageTemplateEnriches logs with application-specific information based on ApplicationMetadata information. The bellow calls will add the application log enricher to the service collection.
// Add service log enricher with default settings
builder.Services.AddApplicationLogEnricher();
// Or configure with options
builder.Services.AddApplicationLogEnricher(options =>
{
options.ApplicationName = true;
options.BuildVersion = true;
options.DeploymentRing = true;
options.EnvironmentName = true;
});
Provides tools for latency data collection and export. The bellow example uses the built-in Console exporter, but custom exporters can be created by implementing the ILatencyDataExporter interface.
// Add latency console data exporter with configuration
builder.Services.AddConsoleLatencyDataExporter(options =>
{
options.OutputCheckpoints = true;
options.OutputMeasures = true;
options.OutputTags = true;
});
In order for the latency data to be exported, a call to ILatencyDataExporter.ExportAsync() is required. This can either be called manually, or by using the Request Latency Middleware inside the Microsoft.AspNetCore.Diagnostics.Middleware package by adding:
// Add Latency Context
builder.Services.AddLatencyContext();
// Add Checkpoints, Measures, Tags
builder.Services.RegisterCheckpointNames("databaseQuery", "externalApiCall");
builder.Services.RegisterMeasureNames("responseTime", "processingTime");
builder.Services.RegisterTagNames("userId", "transactionId");
// Add Console Latency exporter.
builder.Services.AddConsoleLatencyDataExporter();
// Optionally add custom exporters.
builder.Services.AddSingleton<ILatencyDataExporter, MyCustomExporter>();
// Add Request latency telemetry.
builder.Services.AddRequestLatencyTelemetry();
// ...
// Add Request Latency Middleware which will automatically call ExportAsync on all registered latency exporters.
app.UseRequestLatencyTelemetry();
Offers additional logging capabilities like stack trace capturing, exception message inclusion, and log redaction.
// Enable log enrichment.
builder.Logging.EnableEnrichment(options =>
{
options.CaptureStackTraces = true;
options.IncludeExceptionMessage = true;
options.MaxStackTraceLength = 500;
options.UseFileInfoForStackTraces = true;
});
builder.Services.AddApplicationLogEnricher(); // <- This call is required in order for the enricher to be added into the service collection.
// Enable log redaction
builder.Logging.EnableRedaction(options =>
{
options.ApplyDiscriminator = true;
});
builder.Services.AddRedaction(); // <- This call is required in order for the redactor provider to be added into the service collection.
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 5 NuGet packages that depend on Microsoft.Extensions.Telemetry:
| Package | Downloads |
|---|---|
|
Microsoft.Extensions.Http.Diagnostics
Telemetry support for HTTP Client. |
|
|
Microsoft.AspNetCore.Diagnostics.Middleware
ASP.NET Core middleware for collecting high-quality telemetry. |
|
|
Neon.Xunit
Xunit extensions including several additional test fixtures |
|
|
Cratis.Applications
Package Description |
|
|
Tanka.GraphQL.Server
GraphQL Query, Mutation and Subscription library |
Showing the top 5 popular GitHub repositories that depend on Microsoft.Extensions.Telemetry:
| Repository | Stars |
|---|---|
|
Azure/azure-sdk-for-net
This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
|
|
|
dadhi/DryIoc
DryIoc is fast, small, full-featured IoC Container for .NET
|
|
|
mehdihadeli/food-delivery-microservices
🍔 A practical and cloud-native food delivery microservices, built with .Net Aspire, .Net 9, MassTransit, Domain-Driven Design, CQRS, Vertical Slice Architecture, Event-Driven Architecture, and the latest technologies.
|
|
|
DataDog/dd-trace-dotnet
.NET Client Library for Datadog APM
|
|
|
bitbound/ControlR
Open-source, self-hostable remote control and remote access.
|
| Version | Downloads | Last Updated |
|---|---|---|
| 10.7.0 | 303,323 | 6/9/2026 |
| 10.6.0 | 2,234,871 | 5/12/2026 |
| 10.5.0 | 3,712,643 | 4/15/2026 |
| 10.4.0 | 3,624,110 | 3/10/2026 |
| 10.3.0 | 3,775,962 | 2/10/2026 |
| 10.2.0 | 3,860,143 | 1/13/2026 |
| 10.1.0 | 4,448,364 | 12/9/2025 |
| 10.0.0 | 6,920,084 | 11/11/2025 |
| 9.10.0 | 5,189,576 | 10/14/2025 |
| 9.9.0 | 4,733,308 | 9/9/2025 |
| 9.8.0 | 2,273,226 | 8/12/2025 |
| 9.7.0 | 3,670,584 | 7/8/2025 |
| 9.6.0 | 3,022,959 | 6/10/2025 |
| 9.5.0 | 2,716,792 | 5/13/2025 |
| 9.4.0 | 3,696,180 | 4/8/2025 |
| 9.3.0 | 2,087,439 | 3/11/2025 |
| 9.2.0 | 3,817,509 | 2/11/2025 |
| 9.1.0 | 2,311,882 | 1/14/2025 |
| 9.0.0 | 6,852,158 | 11/12/2024 |
| 8.10.0 | 17,144,419 | 10/8/2024 |