Last Updated on February 14, 2023 by Pupli
dotnet add package Serilog.AspNetCore
Select Providers:
https://github.com/serilog/serilog/wiki/Provided-Sinks
Program.cs
builder.Host.UseSerilog((ctx, lc) => lc .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) .Enrich.FromLogContext() .WriteTo.Console() .WriteTo.File("logs/log-.txt", rollingInterval: RollingInterval.Day) .WriteTo.MongoDBBson("mongodb://localhost/interfaces","logs"));
Finally, clean up by removing the remaining configuration for the default logger, including the "Logging"
section from appsettings.*.json files
References
https://github.com/serilog/serilog-aspnetcore
https://blog.datalust.co/using-serilog-in-net-6/
https://github.com/serilog/serilog-sinks-console
https://github.com/serilog/serilog-sinks-file
https://github.com/serilog/serilog-sinks-mongodb
https://github.com/saleem-mirza/serilog-sinks-sqlite