I'm using serilog to log all the Web API trace events in to one file and all the code debug to another file by the below code:
The problem is that the trace.json is also logging Debug events as well which I suspect is because of the minimumLevel filter.
How do I separate the events into two files ?
Tried this Question, but it doesn't write the file at all.
Using latest serilog version.
Log.Logger = new LoggerConfiguration()
.WriteTo.Trace(outputTemplate: "{Timestamp} [{Level}] ({HttpRequestId}|{UserName}) {Message}{NewLine}{Exception}")
.MinimumLevel.Debug()
.WriteTo.Sink(new FileSink(@"E:\log.json", new JsonFormatter(false, null, true), null), LogEventLevel.Debug)
.MinimumLevel.Verbose()
.WriteTo.Sink(new FileSink(@"E:\trace.json", new JsonFormatter(false, null, true), null), LogEventLevel.Verbose)
.Enrich.With<HttpRequestIdEnricher>()
.Enrich.With<UserNameEnricher>()
.Enrich.WithProperty("App", "CarbonFactoryERP")
.CreateLogger();
and below is how I call the logger:
Log.Logger.Debug("Web API Register Method started at {TimeStamp}",DateTime.UtcNow);
Log.Logger.Verbose("{TimeStamp} {Operation} {Operator} {Message} {Category}", rec.Timestamp, rec.Operation, rec.Operator, rec.Message, rec.Category);