You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
NLog target stack overflow when Debug is on and NLog handles ILogger #5822
On version7 (since 7.0.0-rc.2), an ASP.NET Core app that sends ILogger through NLog and has Debug turned on crashes with a StackOverflowException on its first captured event.
To reproduce, use Sentry.Samples.AspNetCore.NLog with Sentry__Debug=true and request /. It also happens with plain builder.Host.UseNLog() (no ReplaceLoggerFactory).
Cause
With Debug on, UseSentry swaps the SDK's diagnostic logger for a MelDiagnosticLogger, so the SDK's own diagnostics go out through ILogger. When NLog handles ILogger, they reach SentryTarget.Write:
The SDK logs a diagnostic (for example "Capturing event.") while the target is writing an entry.
That goes through ILogger to NLog, and back into SentryTarget.Write.
The reentrancy guard catches it, then logs "Reentrant log event detected…" through HubAccessor()?.GetSentryOptions()?.DiagnosticLogger, which is the same MelDiagnosticLogger.
That message goes back into SentryTarget.Write, hits the guard again, and so on until the stack overflows.
On main the guard logs through the target's own Options.DiagnosticLogger, which doesn't loop back. #5585 switched it to the hub's diagnostic logger.
The Serilog sink avoids this by skipping Sentry's own logger categories (SentrySdkNamespaces.IsSentrySdk); the NLog target doesn't.
Possible fixes
Have the reentrancy guard return without logging through the hub's diagnostic logger.
Have the target skip events from Sentry's own categories, as the Serilog sink does.
Activity
linear-code commentedon Oct 28, 2026
NET-891
fix(nlog): stack overflow when Debug is on and NLog handles ILogger (#…
docs(dotnet): Add 6.x to 7.x migration guide for 7.0.0-rc.2 (#20143)