Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 11 additions & 8 deletions src/Sentry/Internal/DefaultSentryStructuredLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,18 @@ private protected override void CaptureLog(SentryLogLevel level, string template
var timestamp = _clock.GetUtcNow();
SentryLog.GetTraceIdAndSpanId(_hub, out var traceId, out var spanId);

string message;
try
{
message = string.Format(CultureInfo.InvariantCulture, template, parameters ?? []);
}
catch (FormatException e)
string message = template;
if (parameters is { Length: > 0 })
{
_options.DiagnosticLogger?.LogError(e, "Template string does not match the provided argument. The Log will be dropped.");
return;
try
{
message = string.Format(CultureInfo.InvariantCulture, template, parameters);
}
catch (FormatException e)
{
_options.DiagnosticLogger?.LogError(e, "Template string does not match the provided argument. The Log will be dropped.");
return;
}
}

ImmutableArray<KeyValuePair<string, object>> @params = default;
Expand Down
27 changes: 27 additions & 0 deletions test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,33 @@

_fixture.Hub.Received(0).CaptureEnvelope(Arg.Any<Envelope>());
}

[Theory]
[InlineData(SentryLogLevel.Trace)]
[InlineData(SentryLogLevel.Debug)]
[InlineData(SentryLogLevel.Info)]
[InlineData(SentryLogLevel.Warning)]
[InlineData(SentryLogLevel.Error)]
[InlineData(SentryLogLevel.Fatal)]
public void Log_WithoutParameters_DoesNotAttachTemplateAttribute(SentryLogLevel level)
{
_fixture.Options.Experimental.EnableLogs = true;
var logger = _fixture.GetSut();

Envelope envelope = null!;
_fixture.Hub.CaptureEnvelope(Arg.Do<Envelope>(arg => envelope = arg));

logger.Log(level, "Message Text");
logger.Flush();

_fixture.Hub.Received(1).CaptureEnvelope(Arg.Any<Envelope>());
var log = envelope.ShouldContainSingleLog();

log.Level.Should().Be(level);
log.Message.Should().Be("Message Text");
log.Template.Should().BeNull();

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-musl-arm64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Fatal)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-musl-arm64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Trace)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-musl-arm64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Debug)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-musl-arm64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Error)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-musl-arm64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Warning)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-musl-arm64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Info)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-musl-arm64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Fatal)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-musl-arm64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Trace)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-musl-arm64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Debug)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-musl-arm64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Error)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-arm64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Fatal)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-arm64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Trace)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-arm64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Debug)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-arm64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Error)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-arm64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Warning)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-arm64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Info)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-arm64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Fatal)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-arm64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Trace)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-arm64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Debug)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-arm64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Error)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-musl-x64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Fatal)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-musl-x64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Trace)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-musl-x64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Debug)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-musl-x64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Error)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-musl-x64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Warning)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-musl-x64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Info)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-musl-x64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Fatal)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-musl-x64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Trace)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-musl-x64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Debug)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-musl-x64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Error)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-x64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Fatal)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-x64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Trace)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-x64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Debug)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-x64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Error)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-x64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Warning)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-x64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Info)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-x64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Fatal)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-x64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Trace)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-x64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Debug)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-x64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Error)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (win-x64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Warning)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (win-x64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Info)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (win-x64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Fatal)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (win-x64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Trace)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (win-x64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Debug)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (win-x64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Error)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (win-arm64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Fatal)

Expected log.Parameters to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (win-arm64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Trace)

Expected log.Parameters to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (win-arm64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Debug)

Expected log.Parameters to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (win-arm64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Error)

Expected log.Parameters to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (win-arm64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Warning)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (win-arm64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Info)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (win-arm64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Fatal)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (win-arm64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Trace)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (win-arm64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Debug)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (win-arm64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Error)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (macos)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Fatal)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (macos)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Trace)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (macos)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Debug)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (macos)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Error)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (macos)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Warning)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (macos)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Info)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (macos)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Fatal)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (macos)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Trace)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (macos)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Debug)

Expected log.Template to be <null>, but found "Message Text".

Check failure on line 110 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (macos)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Error)

Expected log.Template to be <null>, but found "Message Text".
log.Parameters.Should().BeEmpty();

Check failure on line 111 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (win-x64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Fatal)

Expected log.Parameters to be <null>, but found "Message Text".

Check failure on line 111 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (win-x64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Trace)

Expected log.Parameters to be <null>, but found "Message Text".

Check failure on line 111 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (win-x64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Debug)

Expected log.Parameters to be <null>, but found "Message Text".

Check failure on line 111 in test/Sentry.Tests/SentryStructuredLoggerTests.Format.cs

View workflow job for this annotation

GitHub Actions / .NET (win-x64)

Sentry.Tests.SentryStructuredLoggerTests.Log_WithoutParameters_DoesNotAttachTemplateAttribute(level: Error)

Expected log.Parameters to be <null>, but found "Message Text".
}
}

file static class SentryStructuredLoggerExtensions
Expand Down
10 changes: 10 additions & 0 deletions test/Sentry.Tests/SentryStructuredLoggerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,4 +301,14 @@ public static void AssertLog(this SentryStructuredLoggerTests.Fixture fixture, S
{
return new KeyValuePair<string, object?>(name, value);
}

public static SentryLog ShouldContainSingleLog(this Envelope envelope)
{
var envelopeItem = envelope.Items.Should().ContainSingle().Which;
var serializable = envelopeItem.Payload.Should().BeOfType<JsonSerializable>().Which;
var log = serializable.Source.Should().BeOfType<StructuredLog>().Which;

log.Items.Length.Should().Be(1);
return log.Items[0];
}
}
Loading