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, duration hours minute second in high quality that is uploaded to the channel Digital Knack 27 May 2024. Share the link to the video on social media so that your subscribers and friends will also watch this video. This video clip has been viewed 1,073 times and liked it 10 visitors.