Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(logs): flush Logger on UnhandledException that IsTerminating
  • Loading branch information
Flash0ver committed Aug 10, 2025
commit d2bfdd75a779cbb93fdb03792c4b8afcd35be88c
1 change: 1 addition & 0 deletions src/Sentry/Internal/Hub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,7 @@ public async Task FlushAsync(TimeSpan timeout)
{
try
{
Logger.Flush();
await CurrentClient.FlushAsync(timeout).ConfigureAwait(false);
}
catch (Exception e)
Expand Down
30 changes: 30 additions & 0 deletions test/Sentry.Tests/HubTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1624,6 +1624,31 @@ public void Logger_DisableAfterCreate_HasNoEffect()
hub.Logger.Should().BeOfType<DefaultSentryStructuredLogger>();
}

[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 =>
envelope.Items.Single(item => item.Header["type"].Equals("log")).Payload.GetType().IsAssignableFrom(typeof(JsonSerializable))
)
);
await _fixture.Client.Received(1).FlushAsync(
Arg.Is<TimeSpan>(timeout =>
timeout.Equals(_fixture.Options.FlushTimeout)
)
);
hub.Logger.Should().BeOfType<DefaultSentryStructuredLogger>();
}

[Fact]
public void Logger_Dispose_DoesCaptureLog()
{
Expand All @@ -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<TimeSpan>(timeout =>
timeout.Equals(_fixture.Options.ShutdownTimeout)
)
);
hub.Logger.Should().BeOfType<DefaultSentryStructuredLogger>();
}

Expand Down
Loading