diff --git a/benchmarks/Sentry.Benchmarks/BatchProcessorBenchmarks.cs b/benchmarks/Sentry.Benchmarks/BatchProcessorBenchmarks.cs
index 51e0394ee1..0cd225691a 100644
--- a/benchmarks/Sentry.Benchmarks/BatchProcessorBenchmarks.cs
+++ b/benchmarks/Sentry.Benchmarks/BatchProcessorBenchmarks.cs
@@ -27,7 +27,6 @@ public void Setup()
SentryOptions options = new()
{
Dsn = DsnSamples.ValidDsn,
- EnableLogs = true,
};
var batchInterval = Timeout.InfiniteTimeSpan;
diff --git a/benchmarks/Sentry.Benchmarks/SentryStructuredLoggerBenchmarks.cs b/benchmarks/Sentry.Benchmarks/SentryStructuredLoggerBenchmarks.cs
index 8343f9ad24..dd286e3d55 100644
--- a/benchmarks/Sentry.Benchmarks/SentryStructuredLoggerBenchmarks.cs
+++ b/benchmarks/Sentry.Benchmarks/SentryStructuredLoggerBenchmarks.cs
@@ -20,7 +20,6 @@ public void Setup()
SentryOptions options = new()
{
Dsn = DsnSamples.ValidDsn,
- EnableLogs = true,
};
options.SetBeforeSendLog((SentryLog log) =>
{
diff --git a/samples/Sentry.Samples.Console.Basic/Program.cs b/samples/Sentry.Samples.Console.Basic/Program.cs
index 0603caab27..2eeb953bc8 100644
--- a/samples/Sentry.Samples.Console.Basic/Program.cs
+++ b/samples/Sentry.Samples.Console.Basic/Program.cs
@@ -40,8 +40,6 @@
// This option tells Sentry to capture 100% of traces. You still need to start transactions and spans.
options.TracesSampleRate = 1.0;
- // This option enables Sentry Logs created via SentrySdk.Logger.
- options.EnableLogs = true;
options.SetBeforeSendLog(static log =>
{
// A demonstration of how you can drop logs based on some attribute they have
diff --git a/src/Sentry/IHub.cs b/src/Sentry/IHub.cs
index 7831616152..0bb893b261 100644
--- a/src/Sentry/IHub.cs
+++ b/src/Sentry/IHub.cs
@@ -23,7 +23,6 @@ public interface IHub : ISentryClient, ISentryScopeManager
///
/// Available options:
///
- ///
///
///
///
diff --git a/src/Sentry/Internal/DefaultSentryStructuredLogger.cs b/src/Sentry/Internal/DefaultSentryStructuredLogger.cs
index f798e33ede..5c775c775d 100644
--- a/src/Sentry/Internal/DefaultSentryStructuredLogger.cs
+++ b/src/Sentry/Internal/DefaultSentryStructuredLogger.cs
@@ -14,7 +14,6 @@ internal sealed class DefaultSentryStructuredLogger : SentryStructuredLogger, ID
internal DefaultSentryStructuredLogger(IHub hub, SentryOptions options, ISystemClock clock, int batchCount, TimeSpan batchInterval)
{
Debug.Assert(hub.IsEnabled);
- Debug.Assert(options is { EnableLogs: true });
_hub = hub;
_options = options;
diff --git a/src/Sentry/SentryOptions.cs b/src/Sentry/SentryOptions.cs
index 0dbfd7c99b..5f256bd724 100644
--- a/src/Sentry/SentryOptions.cs
+++ b/src/Sentry/SentryOptions.cs
@@ -608,9 +608,14 @@ public void SetBeforeBreadcrumb(Func beforeBreadcrumb)
}
///
- /// When set to , logs are sent to Sentry.
- /// Defaults to .
+ /// When set to , logs captured by the logging integrations
+ /// (Sentry.Extensions.Logging, Sentry.Serilog, Sentry.NLog, Sentry.Log4Net)
+ /// are sent to Sentry. Defaults to .
///
+ ///
+ /// This option does not apply to logs created directly via
+ /// (typically SentrySdk.Logger), which are always sent.
+ ///
///
public bool EnableLogs { get; set; } = false;
diff --git a/src/Sentry/SentryStructuredLogger.cs b/src/Sentry/SentryStructuredLogger.cs
index f7da834ade..60c4353e3a 100644
--- a/src/Sentry/SentryStructuredLogger.cs
+++ b/src/Sentry/SentryStructuredLogger.cs
@@ -13,9 +13,7 @@ internal static SentryStructuredLogger Create(IHub hub, SentryOptions options, I
internal static SentryStructuredLogger Create(IHub hub, SentryOptions options, ISystemClock clock, int batchCount, TimeSpan batchInterval)
{
- return options.EnableLogs
- ? new DefaultSentryStructuredLogger(hub, options, clock, batchCount, batchInterval)
- : DisabledSentryStructuredLogger.Instance;
+ return new DefaultSentryStructuredLogger(hub, options, clock, batchCount, batchInterval);
}
private protected SentryStructuredLogger()
diff --git a/test/Sentry.Tests/HubTests.cs b/test/Sentry.Tests/HubTests.cs
index fcc1bf8f54..74ece9e14f 100644
--- a/test/Sentry.Tests/HubTests.cs
+++ b/test/Sentry.Tests/HubTests.cs
@@ -1994,9 +1994,10 @@ public async Task CaptureTransaction_WithTransactionProfiler_SendsTransactionWit
}
[Fact]
- public void Logger_IsDisabled_DoesNotCaptureLog()
+ public void Logger_EnableLogsDisabled_StillCapturesLog()
{
// Arrange
+ // EnableLogs gates the logging integrations. Logs created directly via this API are always captured.
Assert.False(_fixture.Options.EnableLogs);
var hub = _fixture.GetSut();
@@ -2005,19 +2006,18 @@ public void Logger_IsDisabled_DoesNotCaptureLog()
hub.Logger.Flush();
// Assert
- _fixture.Client.Received(0).CaptureEnvelope(
+ _fixture.Client.Received(1).CaptureEnvelope(
Arg.Is(envelope =>
envelope.Items.Single(item => item.Header["type"].Equals("log")).Payload.GetType().IsAssignableFrom(typeof(JsonSerializable))
)
);
- hub.Logger.Should().BeOfType();
+ hub.Logger.Should().BeOfType();
}
[Fact]
- public void Logger_IsEnabled_DoesCaptureLog()
+ public void Logger_DoesCaptureLog()
{
// Arrange
- _fixture.Options.EnableLogs = true;
var hub = _fixture.GetSut();
// Act
@@ -2033,39 +2033,10 @@ public void Logger_IsEnabled_DoesCaptureLog()
hub.Logger.Should().BeOfType();
}
- [Fact]
- public void Logger_EnableAfterCreate_HasNoEffect()
- {
- // Arrange
- Assert.False(_fixture.Options.EnableLogs);
- var hub = _fixture.GetSut();
-
- // Act
- _fixture.Options.EnableLogs = true;
-
- // Assert
- hub.Logger.Should().BeOfType();
- }
-
- [Fact]
- public void Logger_DisableAfterCreate_HasNoEffect()
- {
- // Arrange
- _fixture.Options.EnableLogs = true;
- var hub = _fixture.GetSut();
-
- // Act
- _fixture.Options.EnableLogs = false;
-
- // Assert
- hub.Logger.Should().BeOfType();
- }
-
[Fact]
public async Task Logger_FlushAsync_DoesCaptureLog()
{
// Arrange
- _fixture.Options.EnableLogs = true;
var hub = _fixture.GetSut();
// Act
@@ -2090,7 +2061,6 @@ await _fixture.Client.Received(1).FlushAsync(
public void Logger_Dispose_DoesCaptureLog()
{
// Arrange
- _fixture.Options.EnableLogs = true;
var hub = _fixture.GetSut();
// Act
diff --git a/test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs b/test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs
index 7222df13ac..280d8e6de9 100644
--- a/test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs
+++ b/test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs
@@ -11,9 +11,8 @@ public partial class SentryStructuredLoggerTests
[InlineData(SentryLogLevel.Warning)]
[InlineData(SentryLogLevel.Error)]
[InlineData(SentryLogLevel.Fatal)]
- public void Log_Enabled_CapturesEnvelope(SentryLogLevel level)
+ public void Log_CapturesEnvelope(SentryLogLevel level)
{
- _fixture.Options.EnableLogs = true;
var logger = _fixture.GetSut();
Envelope envelope = null!;
@@ -33,27 +32,8 @@ public void Log_Enabled_CapturesEnvelope(SentryLogLevel level)
[InlineData(SentryLogLevel.Warning)]
[InlineData(SentryLogLevel.Error)]
[InlineData(SentryLogLevel.Fatal)]
- public void Log_Disabled_DoesNotCaptureEnvelope(SentryLogLevel level)
+ public void Log_ConfigureLog_CapturesEnvelope(SentryLogLevel level)
{
- _fixture.Options.EnableLogs.Should().BeFalse();
- var logger = _fixture.GetSut();
-
- logger.Log(level, "Template string with arguments: {0}, {1}, {2}, {3}", "string", true, 1, 2.2);
- logger.Flush();
-
- _fixture.Hub.Received(0).CaptureEnvelope(Arg.Any());
- }
-
- [Theory]
- [InlineData(SentryLogLevel.Trace)]
- [InlineData(SentryLogLevel.Debug)]
- [InlineData(SentryLogLevel.Info)]
- [InlineData(SentryLogLevel.Warning)]
- [InlineData(SentryLogLevel.Error)]
- [InlineData(SentryLogLevel.Fatal)]
- public void Log_ConfigureLog_Enabled_CapturesEnvelope(SentryLogLevel level)
- {
- _fixture.Options.EnableLogs = true;
var logger = _fixture.GetSut();
Envelope envelope = null!;
@@ -66,24 +46,6 @@ public void Log_ConfigureLog_Enabled_CapturesEnvelope(SentryLogLevel level)
_fixture.AssertEnvelope(envelope, level);
}
- [Theory]
- [InlineData(SentryLogLevel.Trace)]
- [InlineData(SentryLogLevel.Debug)]
- [InlineData(SentryLogLevel.Info)]
- [InlineData(SentryLogLevel.Warning)]
- [InlineData(SentryLogLevel.Error)]
- [InlineData(SentryLogLevel.Fatal)]
- public void Log_ConfigureLog_Disabled_DoesNotCaptureEnvelope(SentryLogLevel level)
- {
- _fixture.Options.EnableLogs.Should().BeFalse();
- var logger = _fixture.GetSut();
-
- logger.Log(level, ConfigureLog, "Template string with arguments: {0}, {1}, {2}, {3}", "string", true, 1, 2.2);
- logger.Flush();
-
- _fixture.Hub.Received(0).CaptureEnvelope(Arg.Any());
- }
-
[Theory]
[InlineData(SentryLogLevel.Trace)]
[InlineData(SentryLogLevel.Debug)]
@@ -93,7 +55,6 @@ public void Log_ConfigureLog_Disabled_DoesNotCaptureEnvelope(SentryLogLevel leve
[InlineData(SentryLogLevel.Fatal)]
public void Log_WithoutParameters_DoesNotAttachTemplateAttribute(SentryLogLevel level)
{
- _fixture.Options.EnableLogs = true;
var logger = _fixture.GetSut();
Envelope envelope = null!;
@@ -123,7 +84,6 @@ public void Log_WithoutParameters_DoesNotAttachTemplateAttribute(SentryLogLevel
[InlineData(SentryLogLevel.Fatal)]
public void Log_InvalidFormatButWithoutParameters_CapturesEnvelope(SentryLogLevel level)
{
- _fixture.Options.EnableLogs = true;
var logger = _fixture.GetSut();
Envelope envelope = null!;
diff --git a/test/Sentry.Tests/SentryStructuredLoggerTests.cs b/test/Sentry.Tests/SentryStructuredLoggerTests.cs
index 66762e06e5..f78266898b 100644
--- a/test/Sentry.Tests/SentryStructuredLoggerTests.cs
+++ b/test/Sentry.Tests/SentryStructuredLoggerTests.cs
@@ -74,10 +74,8 @@ public void Dispose()
}
[Fact]
- public void Create_Enabled_NewDefaultInstance()
+ public void Create_NewDefaultInstance()
{
- _fixture.Options.EnableLogs = true;
-
var instance = _fixture.GetSut();
var other = _fixture.GetSut();
@@ -86,22 +84,20 @@ public void Create_Enabled_NewDefaultInstance()
}
[Fact]
- public void Create_Disabled_CachedDisabledInstance()
+ public void Create_EnableLogsDisabled_NewDefaultInstance()
{
+ // EnableLogs gates the logging integrations, not this API.
_fixture.Options.EnableLogs.Should().BeFalse();
var instance = _fixture.GetSut();
- var other = _fixture.GetSut();
- instance.Should().BeOfType();
- instance.Should().BeSameAs(other);
+ instance.Should().BeOfType();
}
[Fact]
public void Log_WithoutActiveSpan_CapturesEnvelope()
{
_fixture.WithoutActiveSpan();
- _fixture.Options.EnableLogs = true;
var logger = _fixture.GetSut();
Envelope envelope = null!;
@@ -120,7 +116,6 @@ public void Log_WithBeforeSendLog_InvokesCallback()
var invocations = 0;
SentryLog configuredLog = null!;
- _fixture.Options.EnableLogs = true;
_fixture.Options.SetBeforeSendLog((SentryLog log) =>
{
invocations++;
@@ -142,7 +137,6 @@ public void Log_WhenBeforeSendLogReturnsNull_DoesNotCaptureEnvelope()
{
var invocations = 0;
- _fixture.Options.EnableLogs = true;
_fixture.Options.SetBeforeSendLog((SentryLog log) =>
{
invocations++;
@@ -159,7 +153,6 @@ public void Log_WhenBeforeSendLogReturnsNull_DoesNotCaptureEnvelope()
[Fact]
public void Log_InvalidFormat_DoesNotCaptureEnvelope()
{
- _fixture.Options.EnableLogs = true;
var logger = _fixture.GetSut();
logger.LogTrace("Template string with arguments: {0}, {1}, {2}, {3}, {4}", "string", true, 1, 2.2);
@@ -175,7 +168,6 @@ public void Log_InvalidFormat_DoesNotCaptureEnvelope()
[Fact]
public void Log_InvalidConfigureLog_DoesNotCaptureEnvelope()
{
- _fixture.Options.EnableLogs = true;
var logger = _fixture.GetSut();
logger.LogTrace(static (SentryLog log) => throw new InvalidOperationException(), "Template string with arguments: {0}, {1}, {2}, {3}", "string", true, 1, 2.2);
@@ -191,7 +183,6 @@ public void Log_InvalidConfigureLog_DoesNotCaptureEnvelope()
[Fact]
public void Log_InvalidBeforeSendLog_DoesNotCaptureEnvelope()
{
- _fixture.Options.EnableLogs = true;
_fixture.Options.SetBeforeSendLog(static (SentryLog log) => throw new InvalidOperationException());
var logger = _fixture.GetSut();
@@ -208,7 +199,6 @@ public void Log_InvalidBeforeSendLog_DoesNotCaptureEnvelope()
[Fact]
public void Flush_AfterLog_CapturesEnvelope()
{
- _fixture.Options.EnableLogs = true;
var logger = _fixture.GetSut();
Envelope envelope = null!;
@@ -230,7 +220,6 @@ public void Flush_AfterLog_CapturesEnvelope()
[Fact]
public void Dispose_BeforeLog_DoesNotCaptureEnvelope()
{
- _fixture.Options.EnableLogs = true;
var logger = _fixture.GetSut();
var defaultLogger = logger.Should().BeOfType().Which;
@@ -253,7 +242,6 @@ public void Log_WithScopeUser_SetsUserAttributes()
_fixture.Hub.SubstituteConfigureScope(scope);
SentryLog capturedLog = null!;
- _fixture.Options.EnableLogs = true;
_fixture.Options.SetBeforeSendLog((SentryLog log) =>
{
capturedLog = log;
@@ -277,7 +265,6 @@ public void Log_WithoutScopeUser_DoesNotSetUserAttributes()
_fixture.Hub.SubstituteConfigureScope(scope);
SentryLog capturedLog = null!;
- _fixture.Options.EnableLogs = true;
_fixture.Options.SetBeforeSendLog((SentryLog log) =>
{
capturedLog = log;