How to implement Serilog in Asp.Net Core 8.0

Опубликовано: 27 Май 2024
на канале: Digital Knack
1,073
10

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);


Смотрите видео How to implement Serilog in Asp.Net Core 8.0 онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Digital Knack 27 Май 2024, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 1,073 раз и оно понравилось 10 людям.