diff --git a/CHANGELOG.md b/CHANGELOG.md index b841681e99..c685603f23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,19 @@ # Changelog +## Unreleased + +### Fixes + +- Experimental _Structured Logs_: + - Remove `IDisposable` from `SentryStructuredLogger`. Disposal is intended through the owning `IHub` instance. ([#4424](https://github.com/getsentry/sentry-dotnet/pull/4424)) + - Ensure all buffered logs are sent to Sentry when the application terminates unexpectedly. ([#4425](https://github.com/getsentry/sentry-dotnet/pull/4425)) + ## 5.14.1 ### Fixes - Crontabs now support day names (MON-SUN) and allow step values and ranges to be combined ([#4407](https://github.com/getsentry/sentry-dotnet/pull/4407)) - Ensure the correct Sentry Cocoa SDK framework version is used on iOS ([#4411](https://github.com/getsentry/sentry-dotnet/pull/4411)) -- Experimental _Structured Logs_: - - Remove `IDisposable` from `SentryStructuredLogger`. Disposal is intended through the owning `IHub` instance. ([#4424](https://github.com/getsentry/sentry-dotnet/pull/4424)) ### Dependencies diff --git a/src/Sentry/Internal/Hub.cs b/src/Sentry/Internal/Hub.cs index 733cdf2391..1c0d6ebf8b 100644 --- a/src/Sentry/Internal/Hub.cs +++ b/src/Sentry/Internal/Hub.cs @@ -798,6 +798,7 @@ public async Task FlushAsync(TimeSpan timeout) { try { + Logger.Flush(); await CurrentClient.FlushAsync(timeout).ConfigureAwait(false); } catch (Exception e) diff --git a/test/Sentry.Tests/HubTests.cs b/test/Sentry.Tests/HubTests.cs index 9c20fbc0fe..1f7e94ee13 100644 --- a/test/Sentry.Tests/HubTests.cs +++ b/test/Sentry.Tests/HubTests.cs @@ -1624,6 +1624,31 @@ public void Logger_DisableAfterCreate_HasNoEffect() hub.Logger.Should().BeOfType(); } + [Fact] + public async Task Logger_FlushAsync_DoesCaptureLog() + { + // Arrange + _fixture.Options.Experimental.EnableLogs = true; + var hub = _fixture.GetSut(); + + // Act + hub.Logger.LogWarning("Message"); + await hub.FlushAsync(); + + // Assert + _fixture.Client.Received(1).CaptureEnvelope( + Arg.Is(envelope => + envelope.Items.Single(item => item.Header["type"].Equals("log")).Payload.GetType().IsAssignableFrom(typeof(JsonSerializable)) + ) + ); + await _fixture.Client.Received(1).FlushAsync( + Arg.Is(timeout => + timeout.Equals(_fixture.Options.FlushTimeout) + ) + ); + hub.Logger.Should().BeOfType(); + } + [Fact] public void Logger_Dispose_DoesCaptureLog() { @@ -1641,6 +1666,11 @@ public void Logger_Dispose_DoesCaptureLog() envelope.Items.Single(item => item.Header["type"].Equals("log")).Payload.GetType().IsAssignableFrom(typeof(JsonSerializable)) ) ); + _fixture.Client.Received(1).FlushAsync( + Arg.Is(timeout => + timeout.Equals(_fixture.Options.ShutdownTimeout) + ) + ); hub.Logger.Should().BeOfType(); }