diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index acd3bc6..8b34c29 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -26,7 +26,7 @@ jobs:
- name: Setup
uses: actions/setup-dotnet@v4
with:
- dotnet-version: 9.0.x
+ dotnet-version: 10.0.x
- name: Compute build number
shell: bash
run: |
diff --git a/Directory.Version.props b/Directory.Version.props
index 30573e4..44918a7 100644
--- a/Directory.Version.props
+++ b/Directory.Version.props
@@ -1,6 +1,6 @@
- 9.0.2
+ 10.0.0
diff --git a/global.json b/global.json
index db8627a..a517500 100644
--- a/global.json
+++ b/global.json
@@ -1,7 +1,7 @@
{
"sdk": {
- "version": "9.0.100",
- "allowPrerelease": false,
+ "version": "10.0.100",
+ "allowPrerelease": true,
"rollForward": "latestFeature"
}
}
diff --git a/samples/Sample/Sample.csproj b/samples/Sample/Sample.csproj
index 793b13a..d8675b5 100644
--- a/samples/Sample/Sample.csproj
+++ b/samples/Sample/Sample.csproj
@@ -1,7 +1,7 @@
- net9.0
+ net10.0
Exe
@@ -10,8 +10,8 @@
-
-
+
+
diff --git a/samples/SampleWithExternalScope/SampleWithExternalScope.csproj b/samples/SampleWithExternalScope/SampleWithExternalScope.csproj
index 84cb0ac..5b08a3a 100644
--- a/samples/SampleWithExternalScope/SampleWithExternalScope.csproj
+++ b/samples/SampleWithExternalScope/SampleWithExternalScope.csproj
@@ -2,7 +2,7 @@
Exe
- net9.0
+ net10.0
@@ -10,8 +10,8 @@
-
-
+
+
diff --git a/samples/SampleWithMelProviders/SampleWithMelProviders.csproj b/samples/SampleWithMelProviders/SampleWithMelProviders.csproj
index 793b13a..d749346 100644
--- a/samples/SampleWithMelProviders/SampleWithMelProviders.csproj
+++ b/samples/SampleWithMelProviders/SampleWithMelProviders.csproj
@@ -10,8 +10,8 @@
-
-
+
+
diff --git a/serilog-extensions-logging.sln b/serilog-extensions-logging.sln
index baca24a..dd59b32 100644
--- a/serilog-extensions-logging.sln
+++ b/serilog-extensions-logging.sln
@@ -32,6 +32,13 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleWithExternalScope", "
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleWithMelProviders", "samples\SampleWithMelProviders\SampleWithMelProviders.csproj", "{B1454759-126F-4F33-84EE-C8E19541DF79}"
EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{1990627E-914D-4072-A593-E1FCA2CE110D}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{E5A26872-83A7-43A8-8C7D-1C26E56A4FAF}"
+ ProjectSection(SolutionItems) = preProject
+ .github\workflows\ci.yml = .github\workflows\ci.yml
+ EndProjectSection
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -73,6 +80,7 @@ Global
{6D5986FF-EECD-4E75-8BC6-A5F78AB549B2} = {E30F638E-BBBE-4AD1-93CE-48CC69CFEFE1}
{653092A8-CBAD-40AA-A4CE-F8B19D6492C2} = {F2407211-6043-439C-8E06-3641634332E7}
{B1454759-126F-4F33-84EE-C8E19541DF79} = {F2407211-6043-439C-8E06-3641634332E7}
+ {E5A26872-83A7-43A8-8C7D-1C26E56A4FAF} = {1990627E-914D-4072-A593-E1FCA2CE110D}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {811E61C5-3871-4633-AFAE-B35B619C8A10}
diff --git a/src/Serilog.Extensions.Logging/Extensions/Logging/SerilogLoggerProvider.cs b/src/Serilog.Extensions.Logging/Extensions/Logging/SerilogLoggerProvider.cs
index 93dce5f..2ad7738 100644
--- a/src/Serilog.Extensions.Logging/Extensions/Logging/SerilogLoggerProvider.cs
+++ b/src/Serilog.Extensions.Logging/Extensions/Logging/SerilogLoggerProvider.cs
@@ -24,6 +24,7 @@ public sealed class SerilogLoggerProvider : ILoggerProvider, ILogEventEnricher,
// May be null; if it is, Log.Logger will be lazily used
readonly ILogger? _logger;
readonly Action? _dispose;
+ readonly ThreadLocal _scopeCollector = new(() => new ScopeCollector());
#if FEATURE_ASYNCDISPOSABLE
readonly Func? _disposeAsync;
#endif
@@ -90,35 +91,38 @@ public IDisposable BeginScope(T state)
///
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
- List? scopeItems = null;
+ var scopeCollector = _scopeCollector.Value!;
+
for (var scope = CurrentScope; scope != null; scope = scope.Parent)
{
scope.EnrichAndCreateScopeItem(logEvent, propertyFactory, out var scopeItem);
if (scopeItem != null)
{
- scopeItems ??= [];
- scopeItems.Add(scopeItem);
+ scopeCollector.AddItem(scopeItem);
}
}
- scopeItems?.Reverse();
+ scopeCollector.ReverseItems();
- _externalScopeProvider?.ForEachScope((state, accumulatingLogEvent) =>
+ _externalScopeProvider?.ForEachScope(static (state, parameters) =>
{
SerilogLoggerScope.EnrichWithStateAndCreateScopeItem(
- accumulatingLogEvent, propertyFactory, state, update: true, out var scopeItem);
+ parameters.LogEvent,
+ parameters.PropertyFactory,
+ state,
+ update: true,
+ out var scopeItem);
if (scopeItem != null)
{
- scopeItems ??= new List();
- scopeItems.Add(scopeItem);
+ parameters.ScopeCollector.AddItem(scopeItem);
}
- }, logEvent);
+ }, (ScopeCollector: scopeCollector, PropertyFactory: propertyFactory, LogEvent: logEvent));
- if (scopeItems != null)
+ if (scopeCollector.Complete() is { } items)
{
- logEvent.AddPropertyIfAbsent(new LogEventProperty(ScopePropertyName, new SequenceValue(scopeItems)));
+ logEvent.AddPropertyIfAbsent(new LogEventProperty(ScopePropertyName, new SequenceValue(items)));
}
}
@@ -149,4 +153,27 @@ public ValueTask DisposeAsync()
return _disposeAsync?.Invoke() ?? default;
}
#endif
+
+ ///
+ /// A wrapper around a list to allow lazy initialization when iterating through scopes.
+ ///
+ sealed class ScopeCollector
+ {
+ List? _scopeItems;
+
+ public void AddItem(LogEventPropertyValue scopeItem)
+ {
+ _scopeItems ??= [];
+ _scopeItems.Add(scopeItem);
+ }
+
+ public void ReverseItems() => _scopeItems?.Reverse();
+
+ public List? Complete()
+ {
+ var scopeItems = _scopeItems;
+ _scopeItems = null;
+ return scopeItems;
+ }
+ }
}
diff --git a/src/Serilog.Extensions.Logging/Serilog.Extensions.Logging.csproj b/src/Serilog.Extensions.Logging/Serilog.Extensions.Logging.csproj
index 3030973..7e792a5 100644
--- a/src/Serilog.Extensions.Logging/Serilog.Extensions.Logging.csproj
+++ b/src/Serilog.Extensions.Logging/Serilog.Extensions.Logging.csproj
@@ -5,7 +5,7 @@
Microsoft;Serilog Contributors
- net462;netstandard2.0;netstandard2.1;net8.0;net9.0
+ net462;netstandard2.0;netstandard2.1;net8.0;net9.0;net10.0
true
serilog;Microsoft.Extensions.Logging
serilog-extension-nuget.png
@@ -22,7 +22,10 @@
-
+
+
+
+
@@ -37,4 +40,8 @@
$(DefineConstants);FEATURE_ITUPLE;FEATURE_ASYNCDISPOSABLE
+
+
+ $(DefineConstants);FEATURE_ITUPLE;FEATURE_ASYNCDISPOSABLE
+
diff --git a/test/Serilog.Extensions.Logging.Benchmarks/Serilog.Extensions.Logging.Benchmarks.csproj b/test/Serilog.Extensions.Logging.Benchmarks/Serilog.Extensions.Logging.Benchmarks.csproj
index 34aa874..37568a5 100644
--- a/test/Serilog.Extensions.Logging.Benchmarks/Serilog.Extensions.Logging.Benchmarks.csproj
+++ b/test/Serilog.Extensions.Logging.Benchmarks/Serilog.Extensions.Logging.Benchmarks.csproj
@@ -1,7 +1,7 @@
- net8.0;net9.0
+ net8.0;net9.0;net10.0
false
@@ -10,10 +10,10 @@
-
+
-
-
+
+
diff --git a/test/Serilog.Extensions.Logging.Tests/Serilog.Extensions.Logging.Tests.csproj b/test/Serilog.Extensions.Logging.Tests/Serilog.Extensions.Logging.Tests.csproj
index aace2e4..1b232e0 100644
--- a/test/Serilog.Extensions.Logging.Tests/Serilog.Extensions.Logging.Tests.csproj
+++ b/test/Serilog.Extensions.Logging.Tests/Serilog.Extensions.Logging.Tests.csproj
@@ -1,7 +1,7 @@
- net8.0;net9.0;net48
+ net8.0;net9.0;net10.0;net48
false
@@ -14,11 +14,11 @@
-
+
-
-
-
+
+
+