8

I would like to set the logFileName from code but I would like to have all other parameters configurable from the app.config file. If I put some configuration in code and some in app.config, one overwrites the other.

Is this possible?

static private Serilog.Core.Logger CreateLogger(string logFileName)
{
    var config = new LoggerConfiguration()
                        .ReadFrom.AppSettings()
                        .WriteTo.File(logFileName, 
                                      rollingInterval: RollingInterval.Day, 
                                      rollOnFileSizeLimit: true, 
                                      fileSizeLimitBytes: 10000000, 
                                      outputTemplate: "{Timestamp:HH:mm:ss} [{Level}] [{SourceContext}] {Message}{NewLine}{Exception}")
                        .CreateLogger();

    Log.Logger = config;

    return config;
}

I'm using .Net framework 472

Q-bertsuit
  • 3,223
  • 6
  • 30
  • 55

0 Answers0