Skip to content

Instantly share code, notes, and snippets.

@doeringp
Created May 17, 2021 07:07
Show Gist options
  • Save doeringp/81e1dba9301fce4182fc5ad54d4bad95 to your computer and use it in GitHub Desktop.
Save doeringp/81e1dba9301fce4182fc5ad54d4bad95 to your computer and use it in GitHub Desktop.
Samples for structured logging in .NET 5.0
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System.Collections.Generic;
Host.CreateDefaultBuilder()
.ConfigureWebHostDefaults(whb => whb.Configure(app =>
{
var logger = app.ApplicationServices.GetRequiredService<ILogger<Foo>>();
IList<string> list = new[] { "a", "b", "c" };
logger.LogCritical("The list has these elements: {list}", list);
string name = null;
logger.LogCritical("My name is {name}", name);
}))
.Build().Run();
class Foo { }
@doeringp
Copy link
Author

Output:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment