datalust / seq-extensions-logging

Add centralized log collection to ASP.NET Core apps with one line of code.
https://datalust.co/seq
Apache License 2.0
84 stars 12 forks source link

Dispose not working as expected #29

Closed adorrestijn closed 4 years ago

adorrestijn commented 4 years ago

Take this code example:

    static void Main()
    {
        using var factory = LoggerFactory.Create(
            ( builder ) =>
            {
                builder
                    .SetMinimumLevel( LogLevel.Trace )
                    .AddConsole()
                    .AddSeq();
            } );

        var provider = new ServiceCollection()
            .AddSingleton( factory )
            .BuildServiceProvider();

        var logger = provider
            .GetRequiredService<ILoggerFactory>()
            .CreateLogger( "test" );

        logger.LogInformation( "0" );
        logger.LogInformation( "1" );
        logger.LogInformation( "2" );
        logger.LogInformation( "3" );
        logger.LogInformation( "4" );
        logger.LogInformation( "5" );
        logger.LogInformation( "6" );
        logger.LogInformation( "7" );
        logger.LogInformation( "8" );
        logger.LogInformation( "9" );
    }

When I run this, the console is displaying all the log entries. When I remove the 'using' statement before the LoggerFactory, the console is only displaying the first 4 or 5 entries (this is expected behavior).

Now Seq is displaying nothing... Not expected behavior. With the added using statement dispose is called on the LoggerFactory and I would expect that Dispose is also called on the PeriodicBatchingSink so that CloseAndFlush is executed.

When I add a Thread.Sleep( 5000 ), Seq is displaying all entries. To be honest, that is a real ugly solution.

What is wrong here, Do I miss something?

nblumhardt commented 4 years ago

Thank you for the report! Just fixed this in #30, seems LoggingBuilder's behavior slipped under the radar. New dev build 4.0.2-dev is on NuGet, I'll push this through to master/a release build shortly.