Skip to content

feat(logs): add NLog integration#5176

Open
Flash0ver wants to merge 3 commits into
mainfrom
feat/logs-nlog
Open

feat(logs): add NLog integration#5176
Flash0ver wants to merge 3 commits into
mainfrom
feat/logs-nlog

Conversation

@Flash0ver
Copy link
Copy Markdown
Member

closes #5167

Changes

Add NLog integration to Sentry Structured Logging.

Docs

  • TODO

@Flash0ver Flash0ver self-assigned this May 1, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 1, 2026

Codecov Report

❌ Patch coverage is 94.91525% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.19%. Comparing base (7deff34) to head (f558baf).

Files with missing lines Patch % Lines
src/Sentry.NLog/LogLevelExtensions.cs 72.72% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5176      +/-   ##
==========================================
+ Coverage   74.13%   74.19%   +0.06%     
==========================================
  Files         508      510       +2     
  Lines       18282    18341      +59     
  Branches     3574     3583       +9     
==========================================
+ Hits        13553    13609      +56     
- Misses       3860     3862       +2     
- Partials      869      870       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Flash0ver Flash0ver marked this pull request as ready for review May 18, 2026 11:23
@Flash0ver Flash0ver requested a review from jamescrosswell as a code owner May 18, 2026 11:23
Comment on lines +96 to +105
log.TryGetAttribute("sentry.environment", out object? environment).Should().BeTrue();
environment.Should().Be("test-environment");
log.TryGetAttribute("sentry.release", out object? release).Should().BeTrue();
release.Should().Be("test-release");
log.TryGetAttribute("sentry.origin", out object? origin).Should().BeTrue();
origin.Should().Be("auto.log.nlog");
log.TryGetAttribute("sentry.sdk.name", out object? sdkName).Should().BeTrue();
sdkName.Should().Be(Constants.SdkName);
log.TryGetAttribute("sentry.sdk.version", out object? sdkVersion).Should().BeTrue();
sdkVersion.Should().Be(SentryTarget.NameAndVersion.Version);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: reference project Sentry.Testing and simplify assertions with extensions added in #4936

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit f558baf. Configure here.

if (Options.EnableLogs)
{
CaptureStructuredLog(hub, Options, logEvent);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NLog reads EnableLogs from wrong options source

High Severity

The NLog integration checks Options.EnableLogs (the target's own SentryNLogOptions) and passes Options to CaptureStructuredLog, but the Serilog integration explicitly reads from hub.GetSentryOptions() instead, with a detailed comment explaining why. When the SDK is initialized elsewhere (e.g., ASP.NET Core) and InitializeSdk is false, the NLog target's own Options.EnableLogs remains the default false, so structured logs silently won't be sent even though the user enabled them on the actual SDK options. The options passed to SetDefaultAttributes may also carry incorrect Environment/Release values.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit f558baf. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Sentry Logs support to NLog

1 participant