C
C#12mo ago
M B V R K

✅ Why Serilog don't log errors???

Hi guys, I'm trying to logging using Serilog, the logging targeting File, Everything works fine, but when I log error it not logged, In my program.cs the registration of Serilog I did as the following:
// Configure Serilog
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", LogEventLevel.Debug)
.Enrich.FromLogContext()
.WriteTo.File("logs/log.txt", rollingInterval: RollingInterval.Day)
.CreateLogger();
// Configure Serilog
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", LogEventLevel.Debug)
.Enrich.FromLogContext()
.WriteTo.File("logs/log.txt", rollingInterval: RollingInterval.Day)
.CreateLogger();
Please any help to fix this issue, and massive thanks in advance <3
4 Replies
Pobiega
Pobiega12mo ago
when you say "don't log errors"... what exactly do you mean? serilog wont magically start logging exceptions thrown in random parts of your program it will log things logged in serilog with the error log level.
M B V R K
M B V R KOP12mo ago
yeah, you're right, the issue is I only forgot to add the following config :
builder.Services.AddLogging(loggingBuilder =>
{
loggingBuilder.AddSerilog(dispose: true);

loggingBuilder.AddFilter("Microsoft", LogLevel.Information);
});
builder.Services.AddLogging(loggingBuilder =>
{
loggingBuilder.AddSerilog(dispose: true);

loggingBuilder.AddFilter("Microsoft", LogLevel.Information);
});
Pobiega
Pobiega12mo ago
yup!
M B V R K
M B V R KOP12mo ago
Massive thanks, I appreciate
Want results from more Discord servers?
Add your server