serilog / serilog-sinks-rollingfile

Deprecated: new applications should use https://github.com/serilog/serilog-sinks-file instead
Apache License 2.0
61 stars 32 forks source link

Multiple files being created before roll algorithm is invoked #49

Closed stephenpatten closed 7 years ago

stephenpatten commented 7 years ago

Hello,

Given the following setup in an ASP.Net website startup:

var builder = new ContainerBuilder();
builder.Register(c => ConfigureLogger()).As<ILogger>();
builder.Build();

    public static ILogger ConfigureLogger()
    {
        var level = new LoggingLevelSwitch(LogEventLevel.Debug);
        var filePath = ConfigurationManager.AppSettings["serilog:Log:FilePath"] +
            $"RequirementsWS_{Environment.MachineName}_";
        return Log.Logger = new LoggerConfiguration()
            .MinimumLevel.ControlledBy(level)
            .Enrich.FromLogContext()
            .Enrich.WithMachineName()
            .Enrich.WithThreadId()
            .WriteTo.Seq(ConfigurationManager.AppSettings["serilog:write-to:Seq.serverUrl"],
                apiKey: ConfigurationManager.AppSettings["serilog:write-to:Seq.apiKey"],
                controlLevelSwitch: level,
                compact: true)
            .WriteTo.RollingFile(filePath + "{Date}.log",
                outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message}{NewLine}{Exception}")
            .CreateLogger();
    }

I'm wondering what might be causing multiple files to be generated as shown in the attached screenshot.

Thank you, Stephen

snap404

skomis-mm commented 7 years ago

Ensure you register a single instance of ILogger:

builder.Register(c => ConfigureLogger()).As<ILogger>().SingleInstance();

otherwise it will be transient by default

jaslam94 commented 3 years ago

Ensure you register a single instance of ILogger:

builder.Register(c => ConfigureLogger()).As<ILogger>().SingleInstance();

otherwise it will be transient by default

What would be its equivalent in MVC5?