Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions .github/ISSUE_TEMPLATE/02-breaking-change.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ body:
options:
- .NET 8
- .NET 9
- .NET 10 Preview 4
- .NET 10 Preview 5
- .NET 10 Preview 6
- .NET 10 Preview 7
- .NET 10 RC 1
- .NET 10 RC 2
- .NET 10 GA
- .NET 11 Preview 1
- .NEt 11 Preview 2
- .NET 11 Preview 2
- .NET 11 Preview 3
- .NET 11 Preview 4
- .NET 11 Preview 5
- Other (please put exact version in description textbox)
validations:
required: true
Expand Down
1 change: 0 additions & 1 deletion docs/core/diagnostics/metrics-generator.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ Metric methods are constrained to the following:
- Their names must not start with an underscore.
- Their parameter names must not start with an underscore.
- Their first parameter must be <xref:System.Diagnostics.Metrics.Meter> type.
Metric methods are constrained to the following:

## See also

Expand Down
141 changes: 141 additions & 0 deletions docs/core/enrichment/application-log-enricher.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
---
title: Application log enricher
description: Learn how to use the application log enricher to add application-specific information to your telemetry in .NET.
ms.date: 10/14/2025
---

# Application log enricher

The application log enricher augments telemetry logs with application-specific information such as service host details and application metadata. This enricher provides essential context about your application's deployment environment, version information, and service identity that helps with monitoring, debugging, and operational visibility.

You can register the enrichers in an IoC container, and all registered enrichers are automatically picked up by respective telemetry logs, where they enrich the telemetry information.

## Prerequisites

To function properly, this enricher requires that [application metadata](application-metadata.md) is configured and available. The application metadata provides the foundational information that the enricher uses to populate telemetry dimensions.

## Install the package

To get started, install the [📦 Microsoft.Extensions.Telemetry](https://www.nuget.org/packages/Microsoft.Extensions.Telemetry) NuGet package:

### [.NET CLI](#tab/dotnet-cli)

```dotnetcli
dotnet add package Microsoft.Extensions.Telemetry
```

Or, if you're using .NET 10+ SDK:

```dotnetcli
dotnet package add Microsoft.Extensions.Telemetry
```

### [PackageReference](#tab/package-reference)

```xml
<PackageReference Include="Microsoft.Extensions.Telemetry"
Version="*" /> <!-- Adjust version -->
```

---

## Application log enricher

The application log enricher provides application-specific enrichment. The log enricher specifically targets log telemetry and adds standardized dimensions that help identify and categorize log entries by service characteristics.

### Step-by-step configuration

Follow these steps to configure the application log enricher in your application:

#### 1. Configure Application Metadata

First, configure the [Application Metadata](application-metadata.md) by calling the <xref:Microsoft.Extensions.Hosting.ApplicationMetadataHostBuilderExtensions.UseApplicationMetadata%2A> methods:

```csharp
var builder = Host.CreateApplicationBuilder(args);
builder.UseApplicationMetadata()
```

This method automatically picks up values from the <xref:Microsoft.Extensions.Hosting.IHostEnvironment> and saves them to the default configuration section `ambientmetadata:application`.

Alternatively, you can use this method <xref:Microsoft.Extensions.Configuration.ApplicationMetadataConfigurationBuilderExtensions.AddApplicationMetadata(Microsoft.Extensions.Configuration.IConfigurationBuilder,Microsoft.Extensions.Hosting.IHostEnvironment,System.String)>, which registers a configuration provider for application metadata by picking up the values from the <xref:Microsoft.Extensions.Hosting.IHostEnvironment> and adds it to the given configuration section name. Then you use <xref:Microsoft.Extensions.DependencyInjection.ApplicationMetadataServiceCollectionExtensions.AddApplicationMetadata(Microsoft.Extensions.DependencyInjection.IServiceCollection,Microsoft.Extensions.Configuration.IConfigurationSection)> method to register the metadata in the dependency injection container, which allow you to pass <xref:Microsoft.Extensions.Configuration.IConfigurationSection> separately:

```csharp
var builder = Host.CreateApplicationBuilder(args)
.ConfigureAppConfiguration(static (context, builder) =>
builder.AddApplicationMetadata(context.HostingEnvironment));

builder.Services.AddApplicationMetadata(
builder.Configuration.GetSection("ambientmetadata:application")));
```

#### 2. Provide additional configuration (optional)

You can provide additional configuration via `appsettings.json`. There are two properties in the [Application Metadata](application-metadata.md) that don't get values automatically: `BuildVersion` and `DeploymentRing`. If you want to use them, provide values manually:

:::code language="json" source="snippets/servicelogenricher/appsettings.json" range="2-7":::

#### 3. Register the service log enricher

Register the log enricher into the dependency injection container using <xref:Microsoft.Extensions.DependencyInjection.ApplicationEnricherServiceCollectionExtensions.AddServiceLogEnricher(Microsoft.Extensions.DependencyInjection.IServiceCollection)>:

```csharp
serviceCollection.AddServiceLogEnricher();
```

You can enable or disable individual options of the enricher using <xref:Microsoft.Extensions.DependencyInjection.ApplicationEnricherServiceCollectionExtensions.AddServiceLogEnricher(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Action{Microsoft.Extensions.Diagnostics.Enrichment.ApplicationLogEnricherOptions})>:

```csharp
serviceCollection.AddServiceLogEnricher(options =>
{
options.BuildVersion = true;
options.DeploymentRing = true;
});
```

Alternatively, configure options using `appsettings.json`:

:::code language="json" source="snippets/servicelogenricher/appsettings.json" range="8-11":::

And apply the configuration using <xref:Microsoft.Extensions.DependencyInjection.ApplicationEnricherServiceCollectionExtensions.AddServiceLogEnricher(Microsoft.Extensions.DependencyInjection.IServiceCollection,Microsoft.Extensions.Configuration.IConfigurationSection)>:

```csharp
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddServiceLogEnricher(builder.Configuration.GetSection("ApplicationLogEnricherOptions"));

```

### `ApplicationLogEnricherOptions` Configuration options

The service log enricher supports several configuration options through the <xref:Microsoft.Extensions.Diagnostics.Enrichment.ApplicationLogEnricherOptions> class:

| Property | Default Value | Dimension Name | Description |
|----------|---------------|----------------|-------------|
| `EnvironmentName` | true | `deployment.environment` | Environment name from hosting environment or configuration |
| `ApplicationName` | true | `service.name` | Application name from hosting environment or configuration |
| `BuildVersion` | false | `service.version` | Build version from configuration |
| `DeploymentRing` | false | `DeploymentRing` | Deployment ring from configuration |

By default, the enricher includes `EnvironmentName` and `ApplicationName` in log entries. The `BuildVersion` and `DeploymentRing` properties are disabled by default and must be explicitly enabled if needed.

### Complete example

Here's a complete example showing how to set up the service log enricher:

**appsettings.json:**

:::code language="json" source="snippets/servicelogenricher/appsettings.json":::

**Program.cs:**

:::code language="csharp" source="snippets/servicelogenricher/Program.cs" :::

### Enriched log output

With the service log enricher configured, your log output will include service-specific dimensions:

:::code language="json" source="snippets/servicelogenricher/output-full.json" highlight="8-11" :::

## Next steps

- Learn about [application metadata configuration](application-metadata.md)
Loading
Loading