Created
May 17, 2021 07:07
-
-
Save doeringp/81e1dba9301fce4182fc5ad54d4bad95 to your computer and use it in GitHub Desktop.
Samples for structured logging in .NET 5.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output:
![image](https://user-images.githubusercontent.com/20394732/118445913-49692a80-b6ef-11eb-82cc-037a9774ef92.png)