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
ref: shorten Microsoft.Extensions.Logging attribute names
  • Loading branch information
Flash0ver committed Aug 15, 2025
commit c47f4af9a0dbdd779abef8aa96346ff6e95571c5
6 changes: 3 additions & 3 deletions src/Sentry.Extensions.Logging/SentryStructuredLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except

if (_categoryName is not null)
{
log.SetAttribute("microsoft.extensions.logging.category_name", _categoryName);
log.SetAttribute("category.name", _categoryName);
}
if (eventId.Name is not null || eventId.Id != 0)
{
log.SetAttribute("microsoft.extensions.logging.event.id", eventId.Id);
log.SetAttribute("event.id", eventId.Id);
}
if (eventId.Name is not null)
{
log.SetAttribute("microsoft.extensions.logging.event.name", eventId.Name);
log.SetAttribute("event.name", eventId.Name);
}

_hub.Logger.CaptureLog(log);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void CreateLogger_DependencyInjection_CanLog()
logger.LogInformation("message");

Assert.NotNull(capturedLog);
capturedLog.TryGetAttribute("microsoft.extensions.logging.category_name", out object? categoryName).Should().BeTrue();
capturedLog.TryGetAttribute("category.name", out object? categoryName).Should().BeTrue();
categoryName.Should().Be(typeof(SentryAspNetCoreStructuredLoggerProviderTests).FullName);

capturedLog.TryGetAttribute("sentry.sdk.name", out object? name).Should().BeTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void CreateLogger_DependencyInjection_CanLog()
logger.LogInformation("message");

Assert.NotNull(capturedLog);
capturedLog.TryGetAttribute("microsoft.extensions.logging.category_name", out object? categoryName).Should().BeTrue();
capturedLog.TryGetAttribute("category.name", out object? categoryName).Should().BeTrue();
categoryName.Should().Be(typeof(SentryStructuredLoggerProviderTests).FullName);

capturedLog.TryGetAttribute("sentry.sdk.name", out object? name).Should().BeTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ public void Log_LogLevel_CaptureLog(LogLevel logLevel, SentryLogLevel expectedLe
log.AssertAttribute("sentry.release", "my-release");
log.AssertAttribute("sentry.sdk.name", "SDK Name");
log.AssertAttribute("sentry.sdk.version", "SDK Version");
log.AssertAttribute("microsoft.extensions.logging.category_name", "CategoryName");
log.AssertAttribute("microsoft.extensions.logging.event.id", 123);
log.AssertAttribute("microsoft.extensions.logging.event.name", "EventName");
log.AssertAttribute("category.name", _fixture.CategoryName);
log.AssertAttribute("event.id", eventId.Id);
log.AssertAttribute("event.name", eventId.Name!);
}

[Fact]
Expand Down Expand Up @@ -192,7 +192,7 @@ public void Log_WithoutCategoryName_CaptureLog()
logger.Log(LogLevel.Information, new EventId(123, "EventName"), new InvalidOperationException("message"), "Message with {Argument}.", "argument");

var log = _fixture.CapturedLogs.Dequeue();
log.TryGetAttribute("microsoft.extensions.logging.category_name", out object? _).Should().BeFalse();
log.TryGetAttribute("category.name", out object? _).Should().BeFalse();
}

[Fact]
Expand All @@ -216,8 +216,8 @@ public void Log_WithoutEvent_CaptureLog()
logger.Log(LogLevel.Information, new InvalidOperationException("message"), "Message with {Argument}.", "argument");

var log = _fixture.CapturedLogs.Dequeue();
log.TryGetAttribute("microsoft.extensions.logging.event.id", out object? _).Should().BeFalse();
log.TryGetAttribute("microsoft.extensions.logging.event.name", out object? _).Should().BeFalse();
log.TryGetAttribute("event.id", out object? _).Should().BeFalse();
log.TryGetAttribute("event.name", out object? _).Should().BeFalse();
}

[Fact]
Expand All @@ -228,8 +228,8 @@ public void Log_WithoutEventId_CaptureLog()
logger.Log(LogLevel.Information, new EventId(0, "EventName"), new InvalidOperationException("message"), "Message with {Argument}.", "argument");

var log = _fixture.CapturedLogs.Dequeue();
log.AssertAttribute("microsoft.extensions.logging.event.id", 0);
log.AssertAttribute("microsoft.extensions.logging.event.name", "EventName");
log.AssertAttribute("event.id", 0);
log.AssertAttribute("event.name", "EventName");
}

[Fact]
Expand All @@ -240,8 +240,8 @@ public void Log_WithoutEventName_CaptureLog()
logger.Log(LogLevel.Information, new EventId(123), new InvalidOperationException("message"), "Message with {Argument}.", "argument");

var log = _fixture.CapturedLogs.Dequeue();
log.AssertAttribute("microsoft.extensions.logging.event.id", 123);
log.TryGetAttribute("microsoft.extensions.logging.event.name", out object? _).Should().BeFalse();
log.AssertAttribute("event.id", 123);
log.TryGetAttribute("event.name", out object? _).Should().BeFalse();
}

[Theory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void CreateLogger_DependencyInjection_CanLog()
logger.LogInformation("message");

Assert.NotNull(capturedLog);
capturedLog.TryGetAttribute("microsoft.extensions.logging.category_name", out object? categoryName).Should().BeTrue();
capturedLog.TryGetAttribute("category.name", out object? categoryName).Should().BeTrue();
categoryName.Should().Be(typeof(SentryMauiStructuredLoggerProviderTests).FullName);

capturedLog.TryGetAttribute("sentry.sdk.name", out object? name).Should().BeTrue();
Expand Down
Loading