2

I want to create a seperate log file for each HTTP request made to the application. When ever a request is made to the application, it has to generate a log file in the following format

debug20220713.log

debug20220713_001.log

debug20220713_002.log

Here in each log file there should be only one log available.

         Log.Logger = new LoggerConfiguration()  
                        .Enrich.WithExceptionDetails()
                        .Enrich.FromLogContext()
                        .WriteTo.Async(y =>
                            y.Logger(m =>
                            {
                                m.WriteTo.File(
                                    new ExpressionTemplate(jsonErrorTemplate),
                                    "error.log", LogEventLevel.Warning,
                                    rollingInterval: RollingInterval.Day);
                                m.Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Warning || e.Level == LogEventLevel.Error);
                            })
                        )
                        .WriteTo.Async(x =>
                            x.Logger(l =>
                            {
                                l.WriteTo.File(new ExpressionTemplate(jsonLogTemplate),
                                    "debug.log", LogEventLevel.Information,
                                    rollingInterval: RollingInterval.Day);
                                l.Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Information);
                            }))
                        .CreateLogger();

I ended up creating own verision of RollingFileSink which matches my requirement. but internally I still use FileSink class. When I call constructor of FileSink I get this error

"This type and constructor will be removed from the public API in a future version; use WriteTo.File() instead."

Hyder Ahmed
  • 149
  • 2
  • 14

0 Answers0