Skip to content

Commit

Permalink
Update readme in ASP.NET Core with Serilog example (#337)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrei Chasovskikh <[email protected]>
  • Loading branch information
andreycha and Andrei Chasovskikh authored Mar 28, 2024
1 parent 79ef258 commit ebd321d
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions examples/aspnetcore-with-serilog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,13 @@ public static IWebHost BuildWebHost(string[] args) =>
.UseStartup<Startup>()
.UseSerilog((ctx, config) =>
{
config.ReadFrom.Configuration(ctx.Configuration);

// Ensure HttpContextAccessor is accessible
// Ensure HttpContextAccessor is accessible
var httpAccessor = ctx.Configuration.Get<HttpContextAccessor>();

// Create a formatter configuration to se this accessor
var formatterConfig = new EcsTextFormatterConfiguration();
formatterConfig.MapHttpContext(httpAccessor);

// Write events to the console using this configration
var formatter = new EcsTextFormatter(formatterConfig);

config.WriteTo.Console(formatter);
config
.ReadFrom.Configuration(ctx.Configuration)
.Enrich.WithEcsHttpContext(httpAccessor)
.WriteTo.Async(a => a.Console(new EcsTextFormatter()));
})
.UseKestrel()
.Build();
Expand Down

0 comments on commit ebd321d

Please sign in to comment.