Skip to content

Commit 5ad4b1f

Browse files
author
Adam Hathcock
committed
ignore locks and invert define IF
1 parent 328862b commit 5ad4b1f

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,4 @@ FakesAssemblies/
195195
# Visual Studio 6 workspace options file
196196
*.opt
197197
*.orig
198+
project.lock.json

src/Serilog.Framework.Logging/SerilogLoggerProvider.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,33 +56,33 @@ public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
5656
}
5757
}
5858
}
59-
60-
#if NETCORE50 || DOTNET5_4
61-
private System.Threading.AsyncLocal<SerilogLoggerScope> _value = new System.Threading.AsyncLocal<SerilogLoggerScope>();
59+
60+
#if NET451
61+
private readonly string _currentScopeKey = nameof(SerilogLoggerScope) + "#" + Guid.NewGuid().ToString("n");
62+
6263
public SerilogLoggerScope CurrentScope
6364
{
6465
get
6566
{
66-
return _value.Value;
67+
var objectHandle = CallContext.LogicalGetData(_currentScopeKey) as ObjectHandle;
68+
return objectHandle?.Unwrap() as SerilogLoggerScope;
6769
}
6870
set
6971
{
70-
_value.Value = value;
72+
CallContext.LogicalSetData(_currentScopeKey, new ObjectHandle(value));
7173
}
7274
}
7375
#else
74-
private readonly string _currentScopeKey = nameof(SerilogLoggerScope) + "#" + Guid.NewGuid().ToString("n");
75-
76+
private System.Threading.AsyncLocal<SerilogLoggerScope> _value = new System.Threading.AsyncLocal<SerilogLoggerScope>();
7677
public SerilogLoggerScope CurrentScope
7778
{
7879
get
7980
{
80-
var objectHandle = CallContext.LogicalGetData(_currentScopeKey) as ObjectHandle;
81-
return objectHandle?.Unwrap() as SerilogLoggerScope;
81+
return _value.Value;
8282
}
8383
set
8484
{
85-
CallContext.LogicalSetData(_currentScopeKey, new ObjectHandle(value));
85+
_value.Value = value;
8686
}
8787
}
8888
#endif

0 commit comments

Comments
 (0)