Skip to content

Commit fac8d45

Browse files
committed
updating docs
1 parent 190e78f commit fac8d45

File tree

2 files changed

+65
-5
lines changed

2 files changed

+65
-5
lines changed

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

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,38 @@ You can provide additional configuration via `appsettings.json`. There are two p
7777

7878
#### 3. Register the service log enricher
7979

80-
Register the log enricher into the dependency injection container using <xref:Microsoft.Extensions.DependencyInjection.ApplicationEnricherServiceCollectionExtensions.AddServiceLogEnricher(Microsoft.Extensions.DependencyInjection.IServiceCollection)>:
80+
Register the log enricher into the dependency injection container:
81+
82+
### [.NET 10+](#tab/net10-plus)
83+
84+
Starting with .NET 10, use the <xref:Microsoft.Extensions.DependencyInjection.ApplicationEnricherServiceCollectionExtensions.AddApplicationLogEnricher(Microsoft.Extensions.DependencyInjection.IServiceCollection)> method:
85+
86+
```csharp
87+
serviceCollection.AddApplicationLogEnricher();
88+
```
89+
90+
You can enable or disable individual options of the enricher:
91+
92+
```csharp
93+
serviceCollection.AddApplicationLogEnricher(options =>
94+
{
95+
options.BuildVersion = true;
96+
options.DeploymentRing = true;
97+
});
98+
```
99+
100+
### [.NET 9 and earlier](#tab/net9-earlier)
101+
102+
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. Use `AddApplicationLogEnricher` instead.
81106
82107
```csharp
83108
serviceCollection.AddServiceLogEnricher();
84109
```
85110

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})>:
111+
You can enable or disable individual options of the enricher:
87112

88113
```csharp
89114
serviceCollection.AddServiceLogEnricher(options =>
@@ -93,18 +118,30 @@ serviceCollection.AddServiceLogEnricher(options =>
93118
});
94119
```
95120

121+
---
122+
96123
Alternatively, configure options using `appsettings.json`:
97124

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

100-
And apply the configuration using <xref:Microsoft.Extensions.DependencyInjection.ApplicationEnricherServiceCollectionExtensions.AddServiceLogEnricher(Microsoft.Extensions.DependencyInjection.IServiceCollection,Microsoft.Extensions.Configuration.IConfigurationSection)>:
127+
And apply the configuration:
128+
129+
### [.NET 10+](#tab/net10-plus-config)
101130

102131
```csharp
103132
var builder = Host.CreateApplicationBuilder(args);
104-
builder.Services.AddServiceLogEnricher(builder.Configuration.GetSection("ApplicationLogEnricherOptions"));
133+
builder.Services.AddApplicationLogEnricher(builder.Configuration.GetSection("ApplicationLogEnricherOptions"));
134+
```
105135

136+
### [.NET 9 and earlier](#tab/net9-earlier-config)
137+
138+
```csharp
139+
var builder = Host.CreateApplicationBuilder(args);
140+
builder.Services.AddServiceLogEnricher(builder.Configuration.GetSection("ApplicationLogEnricherOptions"));
106141
```
107142

143+
---
144+
108145
### `ApplicationLogEnricherOptions` Configuration options
109146

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

docs/core/enrichment/custom-enricher.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ dotnet package add Microsoft.Extensions.Telemetry.Abstractions
3535

3636
---
3737

38-
## Implementation
38+
## `ILogEnricher` Implementation
3939

4040
Your custom enricher only needs to implement a single <xref:Microsoft.Extensions.Diagnostics.Enrichment.ILogEnricher.Enrich(Microsoft.Extensions.Diagnostics.Enrichment.IEnrichmentTagCollector)> method.
4141
During enrichment, this method is called and given an <xref:Microsoft.Extensions.Diagnostics.Enrichment.IEnrichmentTagCollector> instance. The enricher then calls one of the overloads of
@@ -91,3 +91,26 @@ var builder = Host.CreateApplicationBuilder();
9191
builder.Logging.EnableEnrichment();
9292
builder.Services.AddLogEnricher(new AnotherEnricher("anotherKey", "anotherValue"));
9393
```
94+
95+
## Static log enrichers
96+
97+
.NET provides <xref:Microsoft.Extensions.Diagnostics.Enrichment.IStaticLogEnricher> to enrich logs with immutable properties throughout the application lifecycle. Static enrichers execute once during startup initialization, delivering significant performance benefits over standard enrichers that execute for each log record. This approach is particularly advantageous in high-throughput logging scenarios, as it eliminates the overhead of redundant enrichment operations for data that remains constant, that doesn't change throughout the service's lifetime.
98+
99+
```csharp
100+
public class StaticEnricher : IStaticLogEnricher
101+
{
102+
public void Enrich(IEnrichmentTagCollector collector)
103+
{
104+
collector.Add("app.version", "1.0.0");
105+
collector.Add("environment", "production");
106+
}
107+
}
108+
```
109+
110+
And you register it as shown in the following code <xref:Microsoft.Extensions.DependencyInjection.EnrichmentServiceCollectionExtensions.AddStaticLogEnricher``1(Microsoft.Extensions.DependencyInjection.IServiceCollection)>:
111+
112+
```csharp
113+
var builder = Host.CreateApplicationBuilder(args);
114+
builder.Logging.EnableEnrichment();
115+
builder.Services.AddStaticLogEnricher<StaticEnricher>();
116+
```

0 commit comments

Comments
 (0)