Created
December 11, 2021 21:29
-
-
Save wgross/1d7c7a0b8e1fb5e432c18cca13ad0d0c to your computer and use it in GitHub Desktop.
Serilog Compact Strcuture Json Logging
This file contains hidden or 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
{ | |
"Serilog": { | |
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ], | |
"MinimumLevel": { | |
"Default": "Debug" | |
"Override": { | |
"Microsoft": "Warning", | |
"Microsoft.Hosting.Lifetime": "Information", | |
"TreeStore": "Debug" | |
} | |
}, | |
"WriteTo": [ | |
{ "Name": "Console" }, | |
{ | |
"Name": "File", | |
"Args": { | |
"formatter": "Serilog.Formatting.Compact.CompactJsonFormatter, Serilog.Formatting.Compact", | |
"path": "Logs/log-.json", | |
"rollingInterval": "Day" | |
} | |
} | |
], | |
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ] | |
}, | |
"AllowedHosts": "*" | |
} |
This file contains hidden or 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
public static IHostBuilder CreateHostBuilder(string[] args) => | |
Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder(args) | |
.UseSerilog(ConfigureSerilog) | |
.ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>()); | |
private static void ConfigureSerilog(HostBuilderContext hostBuilderContext, LoggerConfiguration loggerConfiguration) | |
{ | |
loggerConfiguration.ReadFrom.Configuration(hostBuilderContext.Configuration); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment