Skip to content
Draft
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
48 changes: 22 additions & 26 deletions docs/core/enrichment/application-log-enricher.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
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
ms.date: 11/12/2025
---

# Application log enricher
Expand Down Expand Up @@ -39,15 +39,11 @@ dotnet package add Microsoft.Extensions.Telemetry

---

## 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
## Step-by-step configuration

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

#### 1. Configure Application Metadata
### 1. Configure Application Metadata

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

Expand All @@ -69,24 +65,24 @@ builder.Services.AddApplicationMetadata(
builder.Configuration.GetSection("ambientmetadata:application")));
```

#### 2. Provide additional configuration (optional)
### 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":::
:::code language="json" source="snippets/applicationlogenricher/appsettings.json" range="2-7":::

#### 3. Register the service log enricher
### 3. Register the application log enricher

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

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

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})>:
You can enable or disable individual options of the enricher using <xref:Microsoft.Extensions.DependencyInjection.ApplicationEnricherServiceCollectionExtensions.AppApplicationLogEnricher(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Action{Microsoft.Extensions.Diagnostics.Enrichment.ApplicationLogEnricherOptions})>:

```csharp
serviceCollection.AddServiceLogEnricher(options =>
serviceCollection.AppApplicationLogEnricher(options =>
{
options.BuildVersion = true;
options.DeploymentRing = true;
Expand All @@ -95,19 +91,19 @@ serviceCollection.AddServiceLogEnricher(options =>

Alternatively, configure options using `appsettings.json`:

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

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

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

```

### `ApplicationLogEnricherOptions` Configuration options
## `ApplicationLogEnricherOptions` configuration options

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

| Property | Default Value | Dimension Name | Description |
|----------|---------------|----------------|-------------|
Expand All @@ -118,23 +114,23 @@ The service log enricher supports several configuration options through the <xre

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
## Complete example

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

**appsettings.json:**

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

**Program.cs:**

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

### Enriched log output
## Enriched log output

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

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

## Next steps

Expand Down
24 changes: 12 additions & 12 deletions docs/core/enrichment/application-metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,16 @@ Optionally, you can provide values for `BuildVersion` and `DeploymentRing` via t

The following table shows the metadata made available by the provider via <xref:Microsoft.Extensions.Configuration.IConfiguration>:

| Key | Required? | Where the value comes from| Value Example | Description|
|-|-|-|-|-|
| Key | Required? | Where the value comes from | Value example | Description |
|-----|-----------|----------------------------|---------------|-------------|
| `ambientmetadata:application:applicationname` | yes | automatically from `IHostEnvironment` |`myApp` | The application name.|
| `ambientmetadata:application:environmentname` | yes | automatically from `IHostEnvironment` | `Production`, `Development`| The environment the application is deployed to.|
| `ambientmetadata:application:buildversion` | no | configure it in `IConfiguration` | `1.0.0-rc1` | The application's build version.|
| `ambientmetadata:application:deploymentring` | no | configure it in `IConfiguration` | `r0`, `public` | The deployment ring from where the application is running.|

```csharp
var builder = Host.CreateDefaultBuilder(args)
// ApplicationName and EnvironmentName will be imported from `IHostEnvironment`
// ApplicationName and EnvironmentName will be imported from `IHostEnvironment`
// BuildVersion and DeploymentRing will be imported from the "appsettings.json" file.
builder.UseApplicationMetadata();

Expand All @@ -107,15 +107,15 @@ var buildVersion = metadataOptions.Value.BuildVersion;

Your `appsettings.json` can have a section as follows :

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

### Configure with IHostApplicationBuilder

For applications using <xref:Microsoft.Extensions.Hosting.IHostApplicationBuilder>:

```csharp
var builder = Host.CreateApplicationBuilder(args)
// ApplicationName and EnvironmentName will be imported from `IHostEnvironment`
// ApplicationName and EnvironmentName will be imported from `IHostEnvironment`
// BuildVersion and DeploymentRing will be imported from the "appsettings.json" file.
builder.UseApplicationMetadata();

Expand Down Expand Up @@ -158,11 +158,11 @@ await host.RunAsync();

The <xref:Microsoft.Extensions.AmbientMetadata.ApplicationMetadata> class includes the following properties:

| Property | Description |
|----------|-------------|
| `ApplicationName` | The name of the application. |
| `BuildVersion` | The version of the application build. |
| `DeploymentRing` | The deployment ring or stage (for example, Canary, Production). |
| Property | Description |
|-------------------|-----------------------------------------------------------------|
| `ApplicationName` | The name of the application. |
| `BuildVersion` | The version of the application build. |
| `DeploymentRing` | The deployment ring or stage (for example, Canary, Production). |
| `EnvironmentName` | The environment where the application is running (for example, Development, Staging, Production). |

## Use with logging
Expand Down Expand Up @@ -229,10 +229,10 @@ With this configuration, your settings would look like:
{
"myapp": {
"metadata": {
"ApplicationName": "MyWebApi", // Your ApplicationName will be imported from `IHostEnvironment`
"ApplicationName": "MyWebApi", // ApplicationName will be imported from `IHostEnvironment`.
"BuildVersion": "1.0.0",
"DeploymentRing": "Production",
"EnvironmentName": "Production" // Your EnvironmentName will be imported from `IHostEnvironment`
"EnvironmentName": "Production" // EnvironmentName will be imported from `IHostEnvironment`.
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Indented = true
};
});
builder.Services.AddServiceLogEnricher(builder.Configuration.GetSection("ApplicationLogEnricherOptions"));
builder.Services.AddApplicationLogEnricher(builder.Configuration.GetSection("ApplicationLogEnricherOptions"));

Check failure on line 16 in docs/core/enrichment/snippets/applicationlogenricher/Program.cs

View workflow job for this annotation

GitHub Actions / snippets-build

D:\a\docs\docs\docs\core\enrichment\snippets\applicationlogenricher\Program.cs(16,18): error CS1061: 'IServiceCollection' does not contain a definition for 'AddApplicationLogEnricher' and no accessible extension method 'AddApplicationLogEnricher' accepting a first argument of type 'IServiceCollection' could be found (are you missing a using directive or an assembly reference?) [D:\a\docs\docs\docs\core\enrichment\snippets\applicationlogenricher\applogenricher.csproj]

var host = builder.Build();
var logger = host.Services.GetRequiredService<ILogger<Program>>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
57 changes: 57 additions & 0 deletions docs/fundamentals/syslib-diagnostics/extobs0002.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
title: EXTOBS0002 warning
description: Learn about the obsoletions that generate compile-time warning EXTOBS0002.
ms.date: 11/12/2025
f1_keywords:
- extobs0002
ai-usage: ai-assisted
---
# EXTOBS0002: AddServiceLogEnricher is obsolete

The `AddServiceLogEnricher` extension methods have been marked as obsolete starting in .NET 11. These methods had incorrect naming that didn't accurately reflect their functionality. The methods enrich application logs, not service logs, so they have been replaced with correctly named `AddApplicationLogEnricher` methods.

The following APIs are marked obsolete. Use of these APIs generates warning `EXTOBS0002` at compile time.

- <xref:Microsoft.Extensions.DependencyInjection.ApplicationEnricherServiceCollectionExtensions.AddServiceLogEnricher(Microsoft.Extensions.DependencyInjection.IServiceCollection)?displayProperty=nameWithType>
- <xref:Microsoft.Extensions.DependencyInjection.ApplicationEnricherServiceCollectionExtensions.AddServiceLogEnricher(Microsoft.Extensions.DependencyInjection.IServiceCollection,Microsoft.Extensions.Configuration.IConfigurationSection)?displayProperty=nameWithType>
- <xref:Microsoft.Extensions.DependencyInjection.ApplicationEnricherServiceCollectionExtensions.AddServiceLogEnricher(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Action{Microsoft.Extensions.Telemetry.Enrichment.ApplicationLogEnricherOptions})?displayProperty=nameWithType>

## Workarounds

Replace calls to `AddServiceLogEnricher` with the equivalent `AddApplicationLogEnricher` methods. The functionality remains the same, only the method names have been corrected to accurately reflect that they enrich application logs.

For more information, see [Application log enricher](../../core/enrichment/application-log-enricher.md).

## Suppress a warning

If you must use the obsolete APIs, you can suppress the warning in code or in your project file.

To suppress only a single violation, add preprocessor directives to your source file to disable and then re-enable the warning.

```csharp
// Disable the warning.
#pragma warning disable EXTOBS0002

// Code that uses obsolete API.
// ...

// Re-enable the warning.
#pragma warning restore EXTOBS0002
```

To suppress all the `EXTOBS0002` warnings in your project, add a `<NoWarn>` property to your project file.

```xml
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
...
<NoWarn>$(NoWarn);EXTOBS0002</NoWarn>
</PropertyGroup>
</Project>
```

For more information, see [Suppress warnings](obsoletions-overview.md#suppress-warnings).

## See also

- [Application log enricher](../../core/enrichment/application-log-enricher.md)
Loading