From 71d19787aecb9bf4a6697120772d81f45608823f Mon Sep 17 00:00:00 2001 From: Richard Webb Date: Tue, 11 Jun 2024 10:13:35 +0100 Subject: [PATCH 1/9] Update TFMs --- global.json | 1 - .../Enrichers/ThreadNameEnricher.cs | 2 -- .../Serilog.Enrichers.Thread.csproj | 20 ++++++------------- .../ThreadLoggerConfigurationExtensions.cs | 3 --- 4 files changed, 6 insertions(+), 20 deletions(-) delete mode 100644 global.json diff --git a/global.json b/global.json deleted file mode 100644 index 31a5f7f..0000000 --- a/global.json +++ /dev/null @@ -1 +0,0 @@ -{"projects":["src","test"]} \ No newline at end of file diff --git a/src/Serilog.Enrichers.Thread/Enrichers/ThreadNameEnricher.cs b/src/Serilog.Enrichers.Thread/Enrichers/ThreadNameEnricher.cs index d9b8cf4..609b316 100644 --- a/src/Serilog.Enrichers.Thread/Enrichers/ThreadNameEnricher.cs +++ b/src/Serilog.Enrichers.Thread/Enrichers/ThreadNameEnricher.cs @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#if THREAD_NAME using System.Threading; using Serilog.Core; using Serilog.Events; @@ -54,4 +53,3 @@ public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) } } } -#endif \ No newline at end of file diff --git a/src/Serilog.Enrichers.Thread/Serilog.Enrichers.Thread.csproj b/src/Serilog.Enrichers.Thread/Serilog.Enrichers.Thread.csproj index aa25c84..b3f2a6d 100644 --- a/src/Serilog.Enrichers.Thread/Serilog.Enrichers.Thread.csproj +++ b/src/Serilog.Enrichers.Thread/Serilog.Enrichers.Thread.csproj @@ -4,7 +4,12 @@ Enrich Serilog events with properties from the current thread. 3.2.0 Serilog Contributors - net45;netstandard1.0;netstandard2.0 + + net471;net462 + + $(TargetFrameworks);net8.0;net6.0;netstandard2.0 true true Serilog.Enrichers.Thread @@ -25,11 +30,6 @@ - - - - - True @@ -37,12 +37,4 @@ - - $(DefineConstants);THREAD_NAME - - - - $(DefineConstants);THREAD_NAME - - diff --git a/src/Serilog.Enrichers.Thread/ThreadLoggerConfigurationExtensions.cs b/src/Serilog.Enrichers.Thread/ThreadLoggerConfigurationExtensions.cs index 41fb4f3..9ff10c5 100644 --- a/src/Serilog.Enrichers.Thread/ThreadLoggerConfigurationExtensions.cs +++ b/src/Serilog.Enrichers.Thread/ThreadLoggerConfigurationExtensions.cs @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - using System; using System.Threading; using Serilog.Configuration; @@ -39,7 +38,6 @@ public static LoggerConfiguration WithThreadId( return enrichmentConfiguration.With(); } -#if THREAD_NAME /// /// Enrich log events with a ThreadName property containing the . /// @@ -52,6 +50,5 @@ public static LoggerConfiguration WithThreadName( if (enrichmentConfiguration == null) throw new ArgumentNullException(nameof(enrichmentConfiguration)); return enrichmentConfiguration.With(); } -#endif } } From 5b2ce01c952763a3815ae009237e1a6419df9585 Mon Sep 17 00:00:00 2001 From: Richard Webb Date: Tue, 11 Jun 2024 10:35:05 +0100 Subject: [PATCH 2/9] Update to Serilog 4 --- src/Serilog.Enrichers.Thread/Enrichers/ThreadIdEnricher.cs | 2 +- src/Serilog.Enrichers.Thread/Enrichers/ThreadNameEnricher.cs | 4 ++-- src/Serilog.Enrichers.Thread/Serilog.Enrichers.Thread.csproj | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Serilog.Enrichers.Thread/Enrichers/ThreadIdEnricher.cs b/src/Serilog.Enrichers.Thread/Enrichers/ThreadIdEnricher.cs index 2ad07e5..903cd91 100644 --- a/src/Serilog.Enrichers.Thread/Enrichers/ThreadIdEnricher.cs +++ b/src/Serilog.Enrichers.Thread/Enrichers/ThreadIdEnricher.cs @@ -43,7 +43,7 @@ public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) var threadId = Environment.CurrentManagedThreadId; var last = _lastValue; - if (last == null || (int)((ScalarValue)last.Value).Value != threadId) + if (last is null || (int)((ScalarValue)last.Value).Value! != threadId) // no need to synchronize threads on write - just some of them will win _lastValue = last = new LogEventProperty(ThreadIdPropertyName, new ScalarValue(threadId)); diff --git a/src/Serilog.Enrichers.Thread/Enrichers/ThreadNameEnricher.cs b/src/Serilog.Enrichers.Thread/Enrichers/ThreadNameEnricher.cs index 609b316..b0bf499 100644 --- a/src/Serilog.Enrichers.Thread/Enrichers/ThreadNameEnricher.cs +++ b/src/Serilog.Enrichers.Thread/Enrichers/ThreadNameEnricher.cs @@ -41,10 +41,10 @@ public class ThreadNameEnricher : ILogEventEnricher public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) { var threadName = Thread.CurrentThread.Name; - if (threadName != null) + if (threadName is not null) { var last = _lastValue; - if (last == null || (string)((ScalarValue)last.Value).Value != threadName) + if (last is null || (string)((ScalarValue)last.Value).Value! != threadName) // no need to synchronize threads on write - just some of them will win _lastValue = last = new LogEventProperty(ThreadNamePropertyName, new ScalarValue(threadName)); diff --git a/src/Serilog.Enrichers.Thread/Serilog.Enrichers.Thread.csproj b/src/Serilog.Enrichers.Thread/Serilog.Enrichers.Thread.csproj index b3f2a6d..89ba9a7 100644 --- a/src/Serilog.Enrichers.Thread/Serilog.Enrichers.Thread.csproj +++ b/src/Serilog.Enrichers.Thread/Serilog.Enrichers.Thread.csproj @@ -27,7 +27,7 @@ - + From b33c2d588d0ed9cc4923cd6421a6d2b5f0bbe9a9 Mon Sep 17 00:00:00 2001 From: Richard Webb Date: Tue, 11 Jun 2024 10:38:37 +0100 Subject: [PATCH 3/9] Internalize and seal enricher classes --- src/Serilog.Enrichers.Thread/Enrichers/ThreadIdEnricher.cs | 4 ++-- src/Serilog.Enrichers.Thread/Enrichers/ThreadNameEnricher.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Serilog.Enrichers.Thread/Enrichers/ThreadIdEnricher.cs b/src/Serilog.Enrichers.Thread/Enrichers/ThreadIdEnricher.cs index 903cd91..ad683ea 100644 --- a/src/Serilog.Enrichers.Thread/Enrichers/ThreadIdEnricher.cs +++ b/src/Serilog.Enrichers.Thread/Enrichers/ThreadIdEnricher.cs @@ -21,12 +21,12 @@ namespace Serilog.Enrichers /// /// Enriches log events with a ThreadId property containing the . /// - public class ThreadIdEnricher : ILogEventEnricher + sealed class ThreadIdEnricher : ILogEventEnricher { /// /// The property name added to enriched log events. /// - public const string ThreadIdPropertyName = "ThreadId"; + const string ThreadIdPropertyName = "ThreadId"; /// /// The cached last created "ThreadId" property with some thread id. It is likely to be reused frequently so avoiding heap allocations. diff --git a/src/Serilog.Enrichers.Thread/Enrichers/ThreadNameEnricher.cs b/src/Serilog.Enrichers.Thread/Enrichers/ThreadNameEnricher.cs index b0bf499..7bf4ab3 100644 --- a/src/Serilog.Enrichers.Thread/Enrichers/ThreadNameEnricher.cs +++ b/src/Serilog.Enrichers.Thread/Enrichers/ThreadNameEnricher.cs @@ -21,12 +21,12 @@ namespace Serilog.Enrichers /// /// Enriches log events with a ThreadName property containing the . /// - public class ThreadNameEnricher : ILogEventEnricher + sealed class ThreadNameEnricher : ILogEventEnricher { /// /// The property name added to enriched log events. /// - public const string ThreadNamePropertyName = "ThreadName"; + const string ThreadNamePropertyName = "ThreadName"; /// /// The cached last created "ThreadName" property with some thread name. It is likely to be reused frequently so avoiding heap allocations. From a680e479d26e0d6fd44a3b254e2f64a8f5ca0cc0 Mon Sep 17 00:00:00 2001 From: Richard Webb Date: Tue, 11 Jun 2024 10:42:26 +0100 Subject: [PATCH 4/9] Remove AssemblyInfo.cs --- serilog-enrichers-thread.sln | 5 ++--- src/Serilog.Enrichers.Thread/Properties/AssemblyInfo.cs | 6 ------ 2 files changed, 2 insertions(+), 9 deletions(-) delete mode 100644 src/Serilog.Enrichers.Thread/Properties/AssemblyInfo.cs diff --git a/serilog-enrichers-thread.sln b/serilog-enrichers-thread.sln index 9efe3c6..5b1edc3 100644 --- a/serilog-enrichers-thread.sln +++ b/serilog-enrichers-thread.sln @@ -1,14 +1,13 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.28307.329 +# Visual Studio Version 17 +VisualStudioVersion = 17.10.34928.147 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{037440DE-440B-4129-9F7A-09B42D00397E}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assets", "assets", "{E9D1B5E1-DEB9-4A04-8BAB-24EC7240ADAF}" ProjectSection(SolutionItems) = preProject Build.ps1 = Build.ps1 - global.json = global.json README.md = README.md assets\Serilog.snk = assets\Serilog.snk EndProjectSection diff --git a/src/Serilog.Enrichers.Thread/Properties/AssemblyInfo.cs b/src/Serilog.Enrichers.Thread/Properties/AssemblyInfo.cs deleted file mode 100644 index e6a0a37..0000000 --- a/src/Serilog.Enrichers.Thread/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,6 +0,0 @@ -using System; -using System.Reflection; - -[assembly: AssemblyVersion("2.0.0.0")] - -[assembly: CLSCompliant(true)] From bc89a837417e83589568acf177e00549000c1cfa Mon Sep 17 00:00:00 2001 From: Richard Webb Date: Tue, 11 Jun 2024 10:43:55 +0100 Subject: [PATCH 5/9] Remove note about WithThreadName() only working on some .NET versions as it works on all currently supported TFMs --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 84c0264..8b2313a 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,6 @@ Enrich Serilog events with properties from the current thread. -`WithThreadName()` is only supported in .NetStandard 2.0 and .NetFramework 4.5. - ### Getting started Install the package from NuGet: From 14cf77885ac2e3c3386a5ce14b6746ff000c689c Mon Sep 17 00:00:00 2001 From: Richard Webb Date: Tue, 11 Jun 2024 10:52:33 +0100 Subject: [PATCH 6/9] Add the readme file to the nuget package --- src/Serilog.Enrichers.Thread/Serilog.Enrichers.Thread.csproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Serilog.Enrichers.Thread/Serilog.Enrichers.Thread.csproj b/src/Serilog.Enrichers.Thread/Serilog.Enrichers.Thread.csproj index 89ba9a7..d4ea0cb 100644 --- a/src/Serilog.Enrichers.Thread/Serilog.Enrichers.Thread.csproj +++ b/src/Serilog.Enrichers.Thread/Serilog.Enrichers.Thread.csproj @@ -21,6 +21,7 @@ serilog-enricher-nuget.png http://serilog.net Apache-2.0 + README.md false latest enable @@ -35,6 +36,7 @@ True + From 4310b3476d8119a4ea9b0bc7b595c49cd7622e36 Mon Sep 17 00:00:00 2001 From: Richard Webb Date: Tue, 11 Jun 2024 11:59:13 +0100 Subject: [PATCH 7/9] Set version to 4.0 --- src/Serilog.Enrichers.Thread/Serilog.Enrichers.Thread.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Serilog.Enrichers.Thread/Serilog.Enrichers.Thread.csproj b/src/Serilog.Enrichers.Thread/Serilog.Enrichers.Thread.csproj index d4ea0cb..73f0116 100644 --- a/src/Serilog.Enrichers.Thread/Serilog.Enrichers.Thread.csproj +++ b/src/Serilog.Enrichers.Thread/Serilog.Enrichers.Thread.csproj @@ -2,7 +2,7 @@ Enrich Serilog events with properties from the current thread. - 3.2.0 + 4.0.0 Serilog Contributors net471;net462 From cf57f9ff651a660d32ca86fc8d52a5f060bd61c3 Mon Sep 17 00:00:00 2001 From: Richard Webb Date: Thu, 13 Jun 2024 08:12:04 +0100 Subject: [PATCH 8/9] Remove GenerateAssemblyVersionAttribute=false --- src/Serilog.Enrichers.Thread/Serilog.Enrichers.Thread.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Serilog.Enrichers.Thread/Serilog.Enrichers.Thread.csproj b/src/Serilog.Enrichers.Thread/Serilog.Enrichers.Thread.csproj index 73f0116..4a23255 100644 --- a/src/Serilog.Enrichers.Thread/Serilog.Enrichers.Thread.csproj +++ b/src/Serilog.Enrichers.Thread/Serilog.Enrichers.Thread.csproj @@ -3,6 +3,7 @@ Enrich Serilog events with properties from the current thread. 4.0.0 + 4.0.0.0 Serilog Contributors net471;net462 @@ -22,7 +23,6 @@ http://serilog.net Apache-2.0 README.md - false latest enable From 3d45aceaf78d5553dd202378b7f1e35a8ad870a2 Mon Sep 17 00:00:00 2001 From: Richard Webb Date: Thu, 13 Jun 2024 13:40:50 +0100 Subject: [PATCH 9/9] Publish a .snupkg --- Build.ps1 | 2 +- appveyor.yml | 5 ++++- src/Serilog.Enrichers.Thread/Serilog.Enrichers.Thread.csproj | 4 ++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Build.ps1 b/Build.ps1 index b13c813..e716541 100644 --- a/Build.ps1 +++ b/Build.ps1 @@ -20,7 +20,7 @@ foreach ($src in ls src/*) { echo "build: Packaging project in $src" - & dotnet pack -c Release -o ..\..\artifacts --version-suffix=$suffix + & dotnet pack -c Release -o ..\..\artifacts --version-suffix=$suffix -p:ContinuousIntegrationBuild=true if($LASTEXITCODE -ne 0) { exit 1 } Pop-Location diff --git a/appveyor.yml b/appveyor.yml index 622198d..4d88b8d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -7,6 +7,7 @@ build_script: test: off artifacts: - path: artifacts/Serilog.*.nupkg +- path: artifacts/Serilog.*.snupkg deploy: - provider: NuGet api_key: @@ -17,7 +18,9 @@ deploy: - provider: GitHub auth_token: secure: p4LpVhBKxGS5WqucHxFQ5c7C8cP74kbNB0Z8k9Oxx/PMaDQ1+ibmoexNqVU5ZlmX - artifact: /Serilog.*\.nupkg/ + artifacts: + /Serilog.*\.nupkg/ + /Serilog.*\.snupkg/ tag: v$(appveyor_build_version) on: branch: master diff --git a/src/Serilog.Enrichers.Thread/Serilog.Enrichers.Thread.csproj b/src/Serilog.Enrichers.Thread/Serilog.Enrichers.Thread.csproj index 4a23255..67eea47 100644 --- a/src/Serilog.Enrichers.Thread/Serilog.Enrichers.Thread.csproj +++ b/src/Serilog.Enrichers.Thread/Serilog.Enrichers.Thread.csproj @@ -23,6 +23,10 @@ http://serilog.net Apache-2.0 README.md + true + true + true + snupkg latest enable