1

I know there is new update in serilog where you can do conditional logging as shown in below code however that is part of preconfiguration, but I need to write to either to File1 or File2 at run time, well File1 will be used to push data to EventViewer and File2 will be used to push data to SQL database using fluentd.

bool enableFileLogging1 = ...
bool enableFileLogging2 = ...

var builder = new LoggerConfiguration()
    .Enrich.WithExceptionDetails()
    .Enrich.FromLogContext()
    .MinimumLevel.Warning()
    .WriteTo.Conditional(evt => enableFileLogging1, wt => wt.File())
    .WriteTo.Conditional(evt => enableFileLogging2, wt => wt.File(...));

Log.Logger = builder.CreateLogger();
Mysterious288
  • 365
  • 5
  • 24
  • 1
    see: https://stackoverflow.com/questions/38481227/serilog-log-to-different-files – Jonathan Jun 23 '21 at 15:37
  • 1
    Why not use configuration file https://github.com/serilog/serilog-settings-configuration – Ankit Jun 23 '21 at 15:38
  • 1
    Thanks @Jonathan I have seen the post, not sure if I understood completely, there are filters based on file[ like controller/service] but I have a single file where both logs are logged how to apply filter inside a file, kind of subcategorizing. – Mysterious288 Jun 23 '21 at 17:16

0 Answers0