Skip to content

Commit 9741a25

Browse files
committed
add extobs0002 diagnostic
1 parent b5bf597 commit 9741a25

File tree

6 files changed

+79
-26
lines changed

6 files changed

+79
-26
lines changed

docs/core/enrichment/application-log-enricher.md

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Application log enricher
33
description: Learn how to use the application log enricher to add application-specific information to your telemetry in .NET.
4-
ms.date: 10/14/2025
4+
ms.date: 11/12/2025
55
---
66

77
# Application log enricher
@@ -39,15 +39,11 @@ dotnet package add Microsoft.Extensions.Telemetry
3939

4040
---
4141

42-
## Application log enricher
43-
44-
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
4743

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

50-
#### 1. Configure Application Metadata
46+
### 1. Configure Application Metadata
5147

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

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

72-
#### 2. Provide additional configuration (optional)
68+
### 2. Provide additional configuration (optional)
7369

7470
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:
7571

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

78-
#### 3. Register the service log enricher
74+
### 3. Register the application log enricher
7975

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

8278
```csharp
83-
serviceCollection.AddServiceLogEnricher();
79+
serviceCollection.AppApplicationLogEnricher();
8480
```
8581

86-
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})>:
82+
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})>:
8783

8884
```csharp
89-
serviceCollection.AddServiceLogEnricher(options =>
85+
serviceCollection.AppApplicationLogEnricher(options =>
9086
{
9187
options.BuildVersion = true;
9288
options.DeploymentRing = true;
@@ -95,19 +91,19 @@ serviceCollection.AddServiceLogEnricher(options =>
9591

9692
Alternatively, configure options using `appsettings.json`:
9793

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

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

10298
```csharp
10399
var builder = Host.CreateApplicationBuilder(args);
104-
builder.Services.AddServiceLogEnricher(builder.Configuration.GetSection("ApplicationLogEnricherOptions"));
100+
builder.Services.AppApplicationLogEnricher(builder.Configuration.GetSection("ApplicationLogEnricherOptions"));
105101

106102
```
107103

108-
### `ApplicationLogEnricherOptions` Configuration options
104+
## `ApplicationLogEnricherOptions` configuration options
109105

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

112108
| Property | Default Value | Dimension Name | Description |
113109
|----------|---------------|----------------|-------------|
@@ -120,21 +116,21 @@ By default, the enricher includes `EnvironmentName` and `ApplicationName` in log
120116

121117
### Complete example
122118

123-
Here's a complete example showing how to set up the service log enricher:
119+
Here's a complete example showing how to set up the application log enricher:
124120

125121
**appsettings.json:**
126122

127-
:::code language="json" source="snippets/servicelogenricher/appsettings.json":::
123+
:::code language="json" source="snippets/applicationlogenricher/appsettings.json":::
128124

129125
**Program.cs:**
130126

131-
:::code language="csharp" source="snippets/servicelogenricher/Program.cs" :::
127+
:::code language="csharp" source="snippets/applicationlogenricher/Program.cs" :::
132128

133129
### Enriched log output
134130

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

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

139135
## Next steps
140136

docs/core/enrichment/snippets/servicelogenricher/Program.cs renamed to docs/core/enrichment/snippets/applicationlogenricher/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
Indented = true
1414
};
1515
});
16-
builder.Services.AddServiceLogEnricher(builder.Configuration.GetSection("ApplicationLogEnricherOptions"));
16+
builder.Services.AddApplicationLogEnricher(builder.Configuration.GetSection("ApplicationLogEnricherOptions"));
1717

1818
var host = builder.Build();
1919
var logger = host.Services.GetRequiredService<ILogger<Program>>();

docs/core/enrichment/snippets/servicelogenricher/servicelogenricher.csproj renamed to docs/core/enrichment/snippets/applicationlogenricher/applogenricher.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net9.0</TargetFramework>
5+
<TargetFramework>net10.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
</PropertyGroup>

docs/core/enrichment/snippets/servicelogenricher/appsettings.json renamed to docs/core/enrichment/snippets/applicationlogenricher/appsettings.json

File renamed without changes.

docs/core/enrichment/snippets/servicelogenricher/output-full.json renamed to docs/core/enrichment/snippets/applicationlogenricher/output-full.json

File renamed without changes.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
title: EXTOBS0002 warning
3+
description: Learn about the obsoletions that generate compile-time warning EXTOBS0002.
4+
ms.date: 11/12/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 .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.
12+
13+
The following APIs are marked obsolete. Use of these APIs generates warning `EXTOBS0002` at compile time.
14+
15+
- <xref:Microsoft.Extensions.DependencyInjection.ApplicationEnricherServiceCollectionExtensions.AddServiceLogEnricher(Microsoft.Extensions.DependencyInjection.IServiceCollection)?displayProperty=nameWithType>
16+
- <xref:Microsoft.Extensions.DependencyInjection.ApplicationEnricherServiceCollectionExtensions.AddServiceLogEnricher(Microsoft.Extensions.DependencyInjection.IServiceCollection,Microsoft.Extensions.Configuration.IConfigurationSection)?displayProperty=nameWithType>
17+
- <xref:Microsoft.Extensions.DependencyInjection.ApplicationEnricherServiceCollectionExtensions.AddServiceLogEnricher(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Action{Microsoft.Extensions.Telemetry.Enrichment.ApplicationLogEnricherOptions})?displayProperty=nameWithType>
18+
19+
## Workarounds
20+
21+
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+
#pragma warning disable EXTOBS0002
34+
35+
// Code that uses obsolete API.
36+
// ...
37+
38+
// Re-enable the warning.
39+
#pragma warning restore 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+
<Project Sdk="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).
54+
55+
## See also
56+
57+
- [Application log enricher](../../../core/enrichment/application-log-enricher.md)

0 commit comments

Comments
 (0)