diff --git a/README.md b/README.md index 4b5ae29..a1828f6 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ try var app = builder.Build(); app.MapGet("/", () => "Hello World!"); - app.Run(); + await app.RunAsync(); } catch (Exception ex) { @@ -44,7 +44,7 @@ catch (Exception ex) } finally { - Log.CloseAndFlush(); + await Log.CloseAndFlushAsync(); } ``` diff --git a/samples/Sample/Program.cs b/samples/Sample/Program.cs index 7d334df..10cae98 100644 --- a/samples/Sample/Program.cs +++ b/samples/Sample/Program.cs @@ -65,5 +65,5 @@ } finally { - Log.CloseAndFlush(); + await Log.CloseAndFlushAsync(); } diff --git a/test/Serilog.AspNetCore.Tests/SerilogWebHostBuilderExtensionsTests.cs b/test/Serilog.AspNetCore.Tests/SerilogWebHostBuilderExtensionsTests.cs index 61ea07a..ba6ed56 100644 --- a/test/Serilog.AspNetCore.Tests/SerilogWebHostBuilderExtensionsTests.cs +++ b/test/Serilog.AspNetCore.Tests/SerilogWebHostBuilderExtensionsTests.cs @@ -38,6 +38,20 @@ public async Task DisposeShouldBeHandled(bool dispose) Assert.Equal(dispose, logger.IsDisposed); } + + [Fact] + public async Task DisposeAsyncShouldBeHandled() + { + var logger = new DisposeTrackingLogger(); + await using (var web = Setup(logger, dispose: true)) + { + await web.CreateClient().GetAsync("/"); + } + + Assert.Multiple( + () => Assert.True(logger.IsDisposedAsync), + () => Assert.False(logger.IsDisposed)); + } [Fact] public async Task RequestLoggingMiddlewareShouldEnrich() diff --git a/test/Serilog.AspNetCore.Tests/Support/DisposeTrackingLogger.cs b/test/Serilog.AspNetCore.Tests/Support/DisposeTrackingLogger.cs index 14278ef..c6cfebc 100644 --- a/test/Serilog.AspNetCore.Tests/Support/DisposeTrackingLogger.cs +++ b/test/Serilog.AspNetCore.Tests/Support/DisposeTrackingLogger.cs @@ -4,9 +4,10 @@ namespace Serilog.AspNetCore.Tests.Support; -sealed class DisposeTrackingLogger : ILogger, IDisposable +sealed class DisposeTrackingLogger : ILogger, IDisposable, IAsyncDisposable { public bool IsDisposed { get; private set; } + public bool IsDisposedAsync { get; private set; } public ILogger ForContext(ILogEventEnricher enricher) { @@ -352,4 +353,10 @@ public void Dispose() { IsDisposed = true; } + + public ValueTask DisposeAsync() + { + IsDisposedAsync = true; + return default; + } } \ No newline at end of file