File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -165,8 +165,40 @@ Here's a complete example showing how to set up the service log enricher:
165165
166166** Program.cs:**
167167
168+ ### [ .NET 10+] ( #tab/net10-plus-config )
169+
170+ ``` csharp
171+ using System .Text .Json ;
172+ using Microsoft .Extensions .DependencyInjection ;
173+ using Microsoft .Extensions .Hosting ;
174+ using Microsoft .Extensions .Logging ;
175+
176+ var builder = Host .CreateApplicationBuilder (args );
177+ builder .UseApplicationMetadata ();
178+ builder .Logging .EnableEnrichment ();
179+ builder .Logging .AddJsonConsole (op =>
180+ {
181+ op .JsonWriterOptions = new JsonWriterOptions
182+ {
183+ Indented = true
184+ };
185+ });
186+ builder .Services .AddApplicationLogEnricher (builder .Configuration .GetSection (" ApplicationLogEnricherOptions" ));
187+
188+ var host = builder .Build ();
189+ var logger = host .Services .GetRequiredService <ILogger <Program >>();
190+
191+ logger .LogInformation (" This is a sample log message" );
192+
193+ await host .RunAsync ();
194+ ```
195+
196+ ### [ .NET 9 and earlier] ( #tab/net9-earlier-config )
197+
168198:::code language="csharp" source="snippets/servicelogenricher/Program.cs" :::
169199
200+ ---
201+
170202### Enriched log output
171203
172204With the service log enricher configured, your log output will include service-specific dimensions:
You can’t perform that action at this time.
0 commit comments