From 9741a257605fec65edc948f12566194b361fee8e Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Wed, 12 Nov 2025 14:45:01 -0800 Subject: [PATCH 1/3] add extobs0002 diagnostic --- .../enrichment/application-log-enricher.md | 44 +++++++------- .../Program.cs | 2 +- .../applogenricher.csproj} | 2 +- .../appsettings.json | 0 .../output-full.json | 0 .../syslib-diagnostics/extobs0002.md | 57 +++++++++++++++++++ 6 files changed, 79 insertions(+), 26 deletions(-) rename docs/core/enrichment/snippets/{servicelogenricher => applicationlogenricher}/Program.cs (83%) rename docs/core/enrichment/snippets/{servicelogenricher/servicelogenricher.csproj => applicationlogenricher/applogenricher.csproj} (94%) rename docs/core/enrichment/snippets/{servicelogenricher => applicationlogenricher}/appsettings.json (100%) rename docs/core/enrichment/snippets/{servicelogenricher => applicationlogenricher}/output-full.json (100%) create mode 100644 docs/fundamentals/syslib-diagnostics/extobs0002.md diff --git a/docs/core/enrichment/application-log-enricher.md b/docs/core/enrichment/application-log-enricher.md index 2bf801420aecf..fbc75e14e132e 100644 --- a/docs/core/enrichment/application-log-enricher.md +++ b/docs/core/enrichment/application-log-enricher.md @@ -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 @@ -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 methods: @@ -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 : +Register the log enricher into the dependency injection container using : ```csharp -serviceCollection.AddServiceLogEnricher(); +serviceCollection.AppApplicationLogEnricher(); ``` -You can enable or disable individual options of the enricher using : +You can enable or disable individual options of the enricher using : ```csharp -serviceCollection.AddServiceLogEnricher(options => +serviceCollection.AppApplicationLogEnricher(options => { options.BuildVersion = true; options.DeploymentRing = true; @@ -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 : +And apply the configuration using : ```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 class: +The application log enricher supports several configuration options through the class: | Property | Default Value | Dimension Name | Description | |----------|---------------|----------------|-------------| @@ -120,21 +116,21 @@ By default, the enricher includes `EnvironmentName` and `ApplicationName` in log ### 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 -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 diff --git a/docs/core/enrichment/snippets/servicelogenricher/Program.cs b/docs/core/enrichment/snippets/applicationlogenricher/Program.cs similarity index 83% rename from docs/core/enrichment/snippets/servicelogenricher/Program.cs rename to docs/core/enrichment/snippets/applicationlogenricher/Program.cs index 9c7b7d03e929b..bf9f7e32287c9 100644 --- a/docs/core/enrichment/snippets/servicelogenricher/Program.cs +++ b/docs/core/enrichment/snippets/applicationlogenricher/Program.cs @@ -13,7 +13,7 @@ Indented = true }; }); -builder.Services.AddServiceLogEnricher(builder.Configuration.GetSection("ApplicationLogEnricherOptions")); +builder.Services.AddApplicationLogEnricher(builder.Configuration.GetSection("ApplicationLogEnricherOptions")); var host = builder.Build(); var logger = host.Services.GetRequiredService>(); diff --git a/docs/core/enrichment/snippets/servicelogenricher/servicelogenricher.csproj b/docs/core/enrichment/snippets/applicationlogenricher/applogenricher.csproj similarity index 94% rename from docs/core/enrichment/snippets/servicelogenricher/servicelogenricher.csproj rename to docs/core/enrichment/snippets/applicationlogenricher/applogenricher.csproj index 605b504c872e9..f19e9e0c20ff8 100644 --- a/docs/core/enrichment/snippets/servicelogenricher/servicelogenricher.csproj +++ b/docs/core/enrichment/snippets/applicationlogenricher/applogenricher.csproj @@ -2,7 +2,7 @@ Exe - net9.0 + net10.0 enable enable diff --git a/docs/core/enrichment/snippets/servicelogenricher/appsettings.json b/docs/core/enrichment/snippets/applicationlogenricher/appsettings.json similarity index 100% rename from docs/core/enrichment/snippets/servicelogenricher/appsettings.json rename to docs/core/enrichment/snippets/applicationlogenricher/appsettings.json diff --git a/docs/core/enrichment/snippets/servicelogenricher/output-full.json b/docs/core/enrichment/snippets/applicationlogenricher/output-full.json similarity index 100% rename from docs/core/enrichment/snippets/servicelogenricher/output-full.json rename to docs/core/enrichment/snippets/applicationlogenricher/output-full.json diff --git a/docs/fundamentals/syslib-diagnostics/extobs0002.md b/docs/fundamentals/syslib-diagnostics/extobs0002.md new file mode 100644 index 0000000000000..24c422f28fe96 --- /dev/null +++ b/docs/fundamentals/syslib-diagnostics/extobs0002.md @@ -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. + +- +- +- + +## 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 `` property to your project file. + +```xml + + + ... + $(NoWarn);EXTOBS0002 + + +``` + +For more information, see [Suppress warnings](obsoletions-overview.md#suppress-warnings). + +## See also + +- [Application log enricher](../../../core/enrichment/application-log-enricher.md) From cb7d40ab53cd50dcb26d0cd061a7f99df2a2f40e Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Wed, 12 Nov 2025 14:49:52 -0800 Subject: [PATCH 2/3] h3 -> h2 --- docs/core/enrichment/application-log-enricher.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/core/enrichment/application-log-enricher.md b/docs/core/enrichment/application-log-enricher.md index fbc75e14e132e..6e408922d6eca 100644 --- a/docs/core/enrichment/application-log-enricher.md +++ b/docs/core/enrichment/application-log-enricher.md @@ -114,7 +114,7 @@ The application log enricher supports several configuration options through the 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 application log enricher: @@ -126,7 +126,7 @@ Here's a complete example showing how to set up the application log enricher: :::code language="csharp" source="snippets/applicationlogenricher/Program.cs" ::: -### Enriched log output +## Enriched log output With the application log enricher configured, your log output will include service-specific dimensions: From 0da5d5d9b5fd4115131b5aa365ec5498dc8af0cb Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Wed, 12 Nov 2025 15:11:07 -0800 Subject: [PATCH 3/3] fix warnings --- docs/core/enrichment/application-metadata.md | 24 +++++++++---------- .../syslib-diagnostics/extobs0002.md | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/docs/core/enrichment/application-metadata.md b/docs/core/enrichment/application-metadata.md index 08e6dcfad3a3c..fcd1f8aecc268 100644 --- a/docs/core/enrichment/application-metadata.md +++ b/docs/core/enrichment/application-metadata.md @@ -71,8 +71,8 @@ Optionally, you can provide values for `BuildVersion` and `DeploymentRing` via t The following table shows the metadata made available by the provider via : -| 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.| @@ -80,7 +80,7 @@ The following table shows the metadata made available by the provider via 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 @@ -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`. } } } diff --git a/docs/fundamentals/syslib-diagnostics/extobs0002.md b/docs/fundamentals/syslib-diagnostics/extobs0002.md index 24c422f28fe96..28bca2cae8ed3 100644 --- a/docs/fundamentals/syslib-diagnostics/extobs0002.md +++ b/docs/fundamentals/syslib-diagnostics/extobs0002.md @@ -20,7 +20,7 @@ The following APIs are marked obsolete. Use of these APIs generates warning `EXT 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). +For more information, see [Application log enricher](../../core/enrichment/application-log-enricher.md). ## Suppress a warning @@ -54,4 +54,4 @@ For more information, see [Suppress warnings](obsoletions-overview.md#suppress-w ## See also -- [Application log enricher](../../../core/enrichment/application-log-enricher.md) +- [Application log enricher](../../core/enrichment/application-log-enricher.md)