diff --git a/docs/core/enrichment/application-log-enricher.md b/docs/core/enrichment/application-log-enricher.md index 2bf801420aecf..6e408922d6eca 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 | |----------|---------------|----------------|-------------| @@ -118,23 +114,23 @@ The service log enricher supports several configuration options through the : -| 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/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..28bca2cae8ed3 --- /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)