You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
45
-
46
-
### Step-by-step configuration
42
+
## Step-by-step configuration
47
43
48
44
Follow these steps to configure the application log enricher in your application:
49
45
50
-
####1. Configure Application Metadata
46
+
### 1. Configure application metadata
51
47
52
48
First, configure the [Application Metadata](application-metadata.md) by calling the <xref:Microsoft.Extensions.Hosting.ApplicationMetadataHostBuilderExtensions.UseApplicationMetadata%2A> methods:
This method automatically picks up values from the <xref:Microsoft.Extensions.Hosting.IHostEnvironment> and saves them to the default configuration section `ambientmetadata:application`.
60
56
61
-
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:
57
+
Alternatively, you can use the <xref:Microsoft.Extensions.Configuration.ApplicationMetadataConfigurationBuilderExtensions.AddApplicationMetadata(Microsoft.Extensions.Configuration.IConfigurationBuilder,Microsoft.Extensions.Hosting.IHostEnvironment,System.String)> method, which registers a configuration provider for application metadata by picking up the values from the <xref:Microsoft.Extensions.Hosting.IHostEnvironment> and adding them to the given configuration section name. Then you use the <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 allows you to pass <xref:Microsoft.Extensions.Configuration.IConfigurationSection> separately:
####2. Provide additional configuration (optional)
68
+
### 2. Provide additional configuration (optional)
73
69
74
70
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:
Register the log enricher into the dependency injection container:
74
+
### 3. Register the application log enricher
81
75
82
-
### [.NET 10.1+](#tab/net10-plus)
83
-
84
-
Starting with .NET 10, use the <xref:Microsoft.Extensions.DependencyInjection.ApplicationEnricherServiceCollectionExtensions.AddApplicationLogEnricher(Microsoft.Extensions.DependencyInjection.IServiceCollection)> method:
76
+
Register the log enricher into the dependency injection container by calling the <xref:Microsoft.Extensions.DependencyInjection.ApplicationEnricherServiceCollectionExtensions.AddApplicationLogEnricher(Microsoft.Extensions.DependencyInjection.IServiceCollection)> method:
For .NET 9 and earlier versions, use the <xref:Microsoft.Extensions.DependencyInjection.ApplicationEnricherServiceCollectionExtensions.AddServiceLogEnricher(Microsoft.Extensions.DependencyInjection.IServiceCollection)> method:
103
-
104
-
> [!WARNING]
105
-
> The `AddServiceLogEnricher` method is obsolete starting with .NET 10.1. Use `AddApplicationLogEnricher` instead.
106
-
107
-
```csharp
108
-
serviceCollection.AddServiceLogEnricher();
109
-
```
110
-
111
-
You can enable or disable individual options of the enricher:
112
-
113
-
```csharp
114
-
serviceCollection.AddServiceLogEnricher(options=>
115
-
{
116
-
options.BuildVersion=true;
117
-
options.DeploymentRing=true;
118
-
});
119
-
```
120
-
121
-
---
92
+
> [!NOTE]
93
+
> If you're using .NET 9 or an earlier version, call the <xref:Microsoft.Extensions.DependencyInjection.ApplicationEnricherServiceCollectionExtensions.AddServiceLogEnricher(Microsoft.Extensions.DependencyInjection.IServiceCollection)> method instead.
122
94
123
95
Alternatively, configure options using `appsettings.json`:
The service log enricher supports several configuration options through the <xref:Microsoft.Extensions.Diagnostics.Enrichment.ApplicationLogEnricherOptions> class:
108
+
The application log enricher supports several configuration options through the <xref:Microsoft.Extensions.Diagnostics.Enrichment.ApplicationLogEnricherOptions> class:
148
109
149
-
| Property | Default Value| Dimension Name | Description |
|`EnvironmentName`| true |`deployment.environment`| Environment name from hosting environment or configuration |
113
+
|`ApplicationName`| true |`service.name`| Application name from hosting environment or configuration |
114
+
|`BuildVersion`| false |`service.version`| Build version from configuration|
115
+
|`DeploymentRing`| false |`DeploymentRing`| Deployment ring from configuration|
155
116
156
117
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.
157
118
158
-
###Complete example
119
+
## Complete example
159
120
160
-
Here's a complete example showing how to set up the service log enricher:
121
+
Here's a complete example showing how to set up the application log enricher:
|`ambientmetadata:application:applicationname`| yes | automatically from `IHostEnvironment`|`myApp`| The application name.|
77
77
|`ambientmetadata:application:environmentname`| yes | automatically from `IHostEnvironment`|`Production`, `Development`| The environment the application is deployed to.|
78
78
|`ambientmetadata:application:buildversion`| no | configure it in `IConfiguration`|`1.0.0-rc1`| The application's build version.|
79
79
|`ambientmetadata:application:deploymentring`| no | configure it in `IConfiguration`|`r0`, `public`| The deployment ring from where the application is running.|
80
80
81
81
```csharp
82
82
varbuilder=Host.CreateDefaultBuilder(args)
83
-
// ApplicationName and EnvironmentName will be imported from `IHostEnvironment`
83
+
// ApplicationName and EnvironmentName will be imported from `IHostEnvironment`.
84
84
// BuildVersion and DeploymentRing will be imported from the "appsettings.json" file.
85
85
builder.UseApplicationMetadata();
86
86
@@ -105,17 +105,17 @@ var metadataOptions = host.Services.GetRequiredService<IOptions<ApplicationMetad
description: Learn about the obsoletions that generate compile-time warning EXTOBS0002.
4
+
ms.date: 12/22/2025
5
+
f1_keywords:
6
+
- extobs0002
7
+
ai-usage: ai-assisted
8
+
---
9
+
# EXTOBS0002: AddServiceLogEnricher is obsolete
10
+
11
+
The `AddServiceLogEnricher` extension methods have been marked as obsolete starting in package version 10.1.0. 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.
12
+
13
+
The following APIs are marked obsolete. Use of these APIs generates warning `EXTOBS0002` at compile time.
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.
22
+
23
+
For more information, see [Application log enricher](../../core/enrichment/application-log-enricher.md).
24
+
25
+
## Suppress a warning
26
+
27
+
If you must use the obsolete APIs, you can suppress the warning in code or in your project file.
28
+
29
+
To suppress only a single violation, add preprocessor directives to your source file to disable and then re-enable the warning.
30
+
31
+
```csharp
32
+
// Disable the warning.
33
+
#pragmawarningdisable EXTOBS0002
34
+
35
+
// Code that uses obsolete API.
36
+
// ...
37
+
38
+
// Re-enable the warning.
39
+
#pragmawarningrestore EXTOBS0002
40
+
```
41
+
42
+
To suppress all the `EXTOBS0002` warnings in your project, add a `<NoWarn>` property to your project file.
43
+
44
+
```xml
45
+
<ProjectSdk="Microsoft.NET.Sdk">
46
+
<PropertyGroup>
47
+
...
48
+
<NoWarn>$(NoWarn);EXTOBS0002</NoWarn>
49
+
</PropertyGroup>
50
+
</Project>
51
+
```
52
+
53
+
For more information, see [Suppress warnings](obsoletions-overview.md#suppress-warnings).
0 commit comments