Skip to content

feat(logs): add NLog integration - #5176

Merged
jamescrosswell merged 18 commits into
mainfrom
feat/logs-nlog
Jul 16, 2026
Merged

feat(logs): add NLog integration#5176
jamescrosswell merged 18 commits into
mainfrom
feat/logs-nlog

refactor(nlog): simplify HashSet capacity guard

4a228d0
Select commit
Loading
Failed to load commit list.
@sentry/warden / warden: find-bugs completed Jul 15, 2026 in 0s

1 issue

find-bugs: Found 1 issue (1 high)

High

NLog CaptureStructuredLog passes SdkVersion to the Scope parameter of SetDefaultAttributes - `src/Sentry.NLog/SentryTarget.cs:355`

In SentryTarget.Structured.cs, CaptureStructuredLog calls log.SetDefaultAttributes(options, Sdk). The Sdk field is a SdkVersion, but the target method signature is SetDefaultAttributes(SentryOptions options, Scope? scope, SdkVersion? sdk = null), so Sdk is being bound to the Scope? scope parameter. SdkVersion is a sealed class with no implicit conversion to Scope, so this is a type mismatch. Even if it were to resolve, the scope argument would be wrong and the actual SDK version would never be passed, meaning scope-derived attributes (user.id, user.name, user.email, scope Sdk) are never applied to structured logs. Compare the correct Serilog implementation in SentrySink.Structured.cs: var scope = hub.GetScope(); log.SetDefaultAttributes(options, scope, Sdk);. Fix: obtain the scope from the hub (var scope = hub.GetScope();) and call log.SetDefaultAttributes(options, scope, Sdk);.

Also found at:

  • src/Sentry.NLog/SentryTarget.Structured.cs:15

⏱ 14m 9s · 7.3M in / 120.9k out · $10.48

Annotations

Check failure on line 355 in src/Sentry.NLog/SentryTarget.cs

See this annotation in the file changed.

@sentry-warden sentry-warden / warden: find-bugs

NLog CaptureStructuredLog passes SdkVersion to the Scope parameter of SetDefaultAttributes

In `SentryTarget.Structured.cs`, `CaptureStructuredLog` calls `log.SetDefaultAttributes(options, Sdk)`. The `Sdk` field is a `SdkVersion`, but the target method signature is `SetDefaultAttributes(SentryOptions options, Scope? scope, SdkVersion? sdk = null)`, so `Sdk` is being bound to the `Scope? scope` parameter. `SdkVersion` is a sealed class with no implicit conversion to `Scope`, so this is a type mismatch. Even if it were to resolve, the `scope` argument would be wrong and the actual SDK version would never be passed, meaning scope-derived attributes (user.id, user.name, user.email, scope Sdk) are never applied to structured logs. Compare the correct Serilog implementation in `SentrySink.Structured.cs`: `var scope = hub.GetScope(); log.SetDefaultAttributes(options, scope, Sdk);`. Fix: obtain the scope from the hub (`var scope = hub.GetScope();`) and call `log.SetDefaultAttributes(options, scope, Sdk);`.

Check failure on line 15 in src/Sentry.NLog/SentryTarget.Structured.cs

See this annotation in the file changed.

@sentry-warden sentry-warden / warden: find-bugs

[YAU-G66] NLog CaptureStructuredLog passes SdkVersion to the Scope parameter of SetDefaultAttributes (additional location)

In `SentryTarget.Structured.cs`, `CaptureStructuredLog` calls `log.SetDefaultAttributes(options, Sdk)`. The `Sdk` field is a `SdkVersion`, but the target method signature is `SetDefaultAttributes(SentryOptions options, Scope? scope, SdkVersion? sdk = null)`, so `Sdk` is being bound to the `Scope? scope` parameter. `SdkVersion` is a sealed class with no implicit conversion to `Scope`, so this is a type mismatch. Even if it were to resolve, the `scope` argument would be wrong and the actual SDK version would never be passed, meaning scope-derived attributes (user.id, user.name, user.email, scope Sdk) are never applied to structured logs. Compare the correct Serilog implementation in `SentrySink.Structured.cs`: `var scope = hub.GetScope(); log.SetDefaultAttributes(options, scope, Sdk);`. Fix: obtain the scope from the hub (`var scope = hub.GetScope();`) and call `log.SetDefaultAttributes(options, scope, Sdk);`.