diff --git a/CHANGELOG.md b/CHANGELOG.md index 2219c95c1c..9008800b39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ - 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/DefaultSentryStructuredLogger.cs b/src/Sentry/Internal/DefaultSentryStructuredLogger.cs index 37b03babbd..42d61705f1 100644 --- a/src/Sentry/Internal/DefaultSentryStructuredLogger.cs +++ b/src/Sentry/Internal/DefaultSentryStructuredLogger.cs @@ -3,7 +3,7 @@ namespace Sentry.Internal; -internal sealed class DefaultSentryStructuredLogger : SentryStructuredLogger +internal sealed class DefaultSentryStructuredLogger : SentryStructuredLogger, IDisposable { private readonly IHub _hub; private readonly SentryOptions _options; @@ -105,13 +105,8 @@ protected internal override void Flush() } /// - protected override void Dispose(bool disposing) + public void Dispose() { - if (disposing) - { - _batchProcessor.Dispose(); - } - - base.Dispose(disposing); + _batchProcessor.Dispose(); } } diff --git a/src/Sentry/Internal/Hub.cs b/src/Sentry/Internal/Hub.cs index af7de6635d..733cdf2391 100644 --- a/src/Sentry/Internal/Hub.cs +++ b/src/Sentry/Internal/Hub.cs @@ -832,7 +832,7 @@ public void Dispose() #endif Logger.Flush(); - Logger.Dispose(); + (Logger as IDisposable)?.Dispose(); // see Sentry.Internal.DefaultSentryStructuredLogger try { diff --git a/src/Sentry/SentryStructuredLogger.cs b/src/Sentry/SentryStructuredLogger.cs index 0170c28254..19842bbc72 100644 --- a/src/Sentry/SentryStructuredLogger.cs +++ b/src/Sentry/SentryStructuredLogger.cs @@ -8,7 +8,7 @@ namespace Sentry; /// This API is experimental and it may change in the future. /// [Experimental(DiagnosticId.ExperimentalFeature)] -public abstract class SentryStructuredLogger : IDisposable +public abstract class SentryStructuredLogger { internal static SentryStructuredLogger Create(IHub hub, SentryOptions options, ISystemClock clock) => Create(hub, options, clock, 100, TimeSpan.FromSeconds(5)); @@ -123,19 +123,4 @@ public void LogFatal(string template, object[]? parameters = null, Action - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - /// - /// Override in inherited types to clean up managed and unmanaged resources. - /// - /// Invoked from when ; Invoked from Finalize when . - protected virtual void Dispose(bool disposing) - { - } } diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt index ffedc70e00..d2aa1f6c92 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt @@ -1011,11 +1011,9 @@ namespace Sentry public static Sentry.SentryStackTrace FromJson(System.Text.Json.JsonElement json) { } } [System.Diagnostics.CodeAnalysis.Experimental("SENTRY0001")] - public abstract class SentryStructuredLogger : System.IDisposable + public abstract class SentryStructuredLogger { protected abstract void CaptureLog(Sentry.SentryLog log); - public void Dispose() { } - protected virtual void Dispose(bool disposing) { } protected abstract void Flush(); [System.Diagnostics.CodeAnalysis.Experimental("SENTRY0001")] public void LogDebug(string template, object[]? parameters = null, System.Action? configureLog = null) { } diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt index ffedc70e00..d2aa1f6c92 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt @@ -1011,11 +1011,9 @@ namespace Sentry public static Sentry.SentryStackTrace FromJson(System.Text.Json.JsonElement json) { } } [System.Diagnostics.CodeAnalysis.Experimental("SENTRY0001")] - public abstract class SentryStructuredLogger : System.IDisposable + public abstract class SentryStructuredLogger { protected abstract void CaptureLog(Sentry.SentryLog log); - public void Dispose() { } - protected virtual void Dispose(bool disposing) { } protected abstract void Flush(); [System.Diagnostics.CodeAnalysis.Experimental("SENTRY0001")] public void LogDebug(string template, object[]? parameters = null, System.Action? configureLog = null) { } diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt index fb49f7c839..b5093e14bd 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt @@ -971,11 +971,9 @@ namespace Sentry public void WriteTo(System.Text.Json.Utf8JsonWriter writer, Sentry.Extensibility.IDiagnosticLogger? logger) { } public static Sentry.SentryStackTrace FromJson(System.Text.Json.JsonElement json) { } } - public abstract class SentryStructuredLogger : System.IDisposable + public abstract class SentryStructuredLogger { protected abstract void CaptureLog(Sentry.SentryLog log); - public void Dispose() { } - protected virtual void Dispose(bool disposing) { } protected abstract void Flush(); public void LogDebug(string template, object[]? parameters = null, System.Action? configureLog = null) { } public void LogError(string template, object[]? parameters = null, System.Action? configureLog = null) { } diff --git a/test/Sentry.Tests/SentryStructuredLoggerTests.cs b/test/Sentry.Tests/SentryStructuredLoggerTests.cs index aeb121badc..b64b258e69 100644 --- a/test/Sentry.Tests/SentryStructuredLoggerTests.cs +++ b/test/Sentry.Tests/SentryStructuredLoggerTests.cs @@ -260,7 +260,8 @@ public void Dispose_BeforeLog_DoesNotCaptureEnvelope() _fixture.Options.Experimental.EnableLogs = true; var logger = _fixture.GetSut(); - logger.Dispose(); + var defaultLogger = logger.Should().BeOfType().Which; + defaultLogger.Dispose(); logger.LogTrace("Template string with arguments: {0}, {1}, {2}, {3}", ["string", true, 1, 2.2], ConfigureLog); _fixture.Hub.Received(0).CaptureEnvelope(Arg.Any());