Skip to content

Commit 5acfa5e

Browse files
fix(serilog): make the UseSerilog warning check atomic
Emit can run concurrently, so the check-then-set on the warned flag could let more than one thread log the warning. Part of #5245 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 0aada87 commit 5acfa5e

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

‎src/Sentry.Serilog/SentrySink.cs‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ internal static readonly SdkVersion NameAndVersion
2727
private readonly Func<IHub> _hubAccessor;
2828
private readonly ISystemClock _clock;
2929

30-
private volatile bool _checkedUseSerilog;
30+
private int _checkedUseSerilog;
3131

3232
public SentrySink(SentrySerilogOptions options)
3333
: this(
@@ -160,12 +160,11 @@ private void InnerEmit(LogEvent logEvent)
160160

161161
private void WarnIfUseSerilogNotCalled(SentryOptions options)
162162
{
163-
if (_checkedUseSerilog)
163+
if (Interlocked.Exchange(ref _checkedUseSerilog, 1) != 0)
164164
{
165165
return;
166166
}
167167

168-
_checkedUseSerilog = true;
169168
if (!options.HasSerilogScopeEventProcessor())
170169
{
171170
options.LogWarning(

0 commit comments

Comments
 (0)