In this tutorial you will learn how to implement serilog logging in asp.net core 8.0.
Here is the appsettings.json code:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"Serilog": {
"Using": [ "Serilog.Sinks.File" ],
"MinimumLevel": {
"Default": "Debug"
},
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "D:\\logs\\APIlog-.log",
"rollingInterval": "Day",
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss zzz} {CorrelationId} [{Level:u3}] {Username} {Message:lj}{Exception}{NewLine}"
}
}
]
},
"AllowedHosts": "*"
}
Here is the code snippet to paste in Program.cs:
var _logger = new LoggerConfiguration()
.ReadFrom.Configuration(builder.Configuration)
.Enrich.FromLogContext().CreateLogger();
builder.Logging.ClearProviders();
builder.Logging.AddSerilog(_logger);
Watch video How to implement Serilog in Asp.Net Core 8.0 online without registration, duration hours minute second in high quality. This video was added by user Digital Knack 27 May 2024, don't forget to share it with your friends and acquaintances, it has been viewed on our site 1,07 once and liked it 1 people.