I want to separate my logs in three different parts. Searched for logging libraries and the best one I found is Serilog.
- write http request logs to daily rolling txt files.
- write logs containing exceptions to Seq.
- write all logs except http request logs to a local SQLite database (for users access).
Used the following code but nothing works:
new LoggerConfiguration().Enrich.WithExceptionDetails(new DestructuringOptionsBuilder()
.WithDefaultDestructurers()
.WithRootName("Message").WithRootName("Exception").WithRootName("Exception"))
.Enrich.WithProperty("App.Version", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version?.ToString() ?? "0.0.0.0")
.Enrich.WithMachineName()
.Enrich.WithEnvironmentUserName()
.WriteTo.SQLite(GetFilePath("logs.db"))
.Filter.ByIncludingOnly(Matching.FromSource("Serilog.AspNetCore.RequestLoggingMiddleware"))
.WriteTo.File(
GetFilePath("access.log"),
rollingInterval: RollingInterval.Day,
retainedFileCountLimit: 31
)
.Filter.ByIncludingOnly(LogEvent => LogEvent.Exception != null)
.WriteTo.Seq("https://mylogger.appserver.com/")
Removed second filter (request logs) and now it just writes exception logs in both Seq and local SQLite db.