Skip to content

Commit 602315b

Browse files
authored
Merge pull request #22 from Numpsy/updates
Updates for Serilog 4
2 parents db33d4f + 3d45ace commit 602315b

10 files changed

+29
-43
lines changed

Build.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ foreach ($src in ls src/*) {
2020

2121
echo "build: Packaging project in $src"
2222

23-
& dotnet pack -c Release -o ..\..\artifacts --version-suffix=$suffix
23+
& dotnet pack -c Release -o ..\..\artifacts --version-suffix=$suffix -p:ContinuousIntegrationBuild=true
2424
if($LASTEXITCODE -ne 0) { exit 1 }
2525

2626
Pop-Location

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
Enrich Serilog events with properties from the current thread.
44

5-
`WithThreadName()` is only supported in .NetStandard 2.0 and .NetFramework 4.5.
6-
75
### Getting started
86

97
Install the package from NuGet:

appveyor.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ build_script:
77
test: off
88
artifacts:
99
- path: artifacts/Serilog.*.nupkg
10+
- path: artifacts/Serilog.*.snupkg
1011
deploy:
1112
- provider: NuGet
1213
api_key:
@@ -17,7 +18,9 @@ deploy:
1718
- provider: GitHub
1819
auth_token:
1920
secure: p4LpVhBKxGS5WqucHxFQ5c7C8cP74kbNB0Z8k9Oxx/PMaDQ1+ibmoexNqVU5ZlmX
20-
artifact: /Serilog.*\.nupkg/
21+
artifacts:
22+
/Serilog.*\.nupkg/
23+
/Serilog.*\.snupkg/
2124
tag: v$(appveyor_build_version)
2225
on:
2326
branch: master

global.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

serilog-enrichers-thread.sln

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 15
4-
VisualStudioVersion = 15.0.28307.329
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.10.34928.147
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{037440DE-440B-4129-9F7A-09B42D00397E}"
77
EndProject
88
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assets", "assets", "{E9D1B5E1-DEB9-4A04-8BAB-24EC7240ADAF}"
99
ProjectSection(SolutionItems) = preProject
1010
Build.ps1 = Build.ps1
11-
global.json = global.json
1211
README.md = README.md
1312
assets\Serilog.snk = assets\Serilog.snk
1413
EndProjectSection

src/Serilog.Enrichers.Thread/Enrichers/ThreadIdEnricher.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ namespace Serilog.Enrichers
2121
/// <summary>
2222
/// Enriches log events with a ThreadId property containing the <see cref="Environment.CurrentManagedThreadId"/>.
2323
/// </summary>
24-
public class ThreadIdEnricher : ILogEventEnricher
24+
sealed class ThreadIdEnricher : ILogEventEnricher
2525
{
2626
/// <summary>
2727
/// The property name added to enriched log events.
2828
/// </summary>
29-
public const string ThreadIdPropertyName = "ThreadId";
29+
const string ThreadIdPropertyName = "ThreadId";
3030

3131
/// <summary>
3232
/// The cached last created "ThreadId" property with some thread id. It is likely to be reused frequently so avoiding heap allocations.
@@ -43,7 +43,7 @@ public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
4343
var threadId = Environment.CurrentManagedThreadId;
4444

4545
var last = _lastValue;
46-
if (last == null || (int)((ScalarValue)last.Value).Value != threadId)
46+
if (last is null || (int)((ScalarValue)last.Value).Value! != threadId)
4747
// no need to synchronize threads on write - just some of them will win
4848
_lastValue = last = new LogEventProperty(ThreadIdPropertyName, new ScalarValue(threadId));
4949

src/Serilog.Enrichers.Thread/Enrichers/ThreadNameEnricher.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#if THREAD_NAME
1615
using System.Threading;
1716
using Serilog.Core;
1817
using Serilog.Events;
@@ -22,12 +21,12 @@ namespace Serilog.Enrichers
2221
/// <summary>
2322
/// Enriches log events with a ThreadName property containing the <see cref="Thread.CurrentThread"/> <see cref="Thread.Name"/>.
2423
/// </summary>
25-
public class ThreadNameEnricher : ILogEventEnricher
24+
sealed class ThreadNameEnricher : ILogEventEnricher
2625
{
2726
/// <summary>
2827
/// The property name added to enriched log events.
2928
/// </summary>
30-
public const string ThreadNamePropertyName = "ThreadName";
29+
const string ThreadNamePropertyName = "ThreadName";
3130

3231
/// <summary>
3332
/// The cached last created "ThreadName" property with some thread name. It is likely to be reused frequently so avoiding heap allocations.
@@ -42,10 +41,10 @@ public class ThreadNameEnricher : ILogEventEnricher
4241
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
4342
{
4443
var threadName = Thread.CurrentThread.Name;
45-
if (threadName != null)
44+
if (threadName is not null)
4645
{
4746
var last = _lastValue;
48-
if (last == null || (string)((ScalarValue)last.Value).Value != threadName)
47+
if (last is null || (string)((ScalarValue)last.Value).Value! != threadName)
4948
// no need to synchronize threads on write - just some of them will win
5049
_lastValue = last = new LogEventProperty(ThreadNamePropertyName, new ScalarValue(threadName));
5150

@@ -54,4 +53,3 @@ public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
5453
}
5554
}
5655
}
57-
#endif

src/Serilog.Enrichers.Thread/Properties/AssemblyInfo.cs

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/Serilog.Enrichers.Thread/Serilog.Enrichers.Thread.csproj

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22

33
<PropertyGroup>
44
<Description>Enrich Serilog events with properties from the current thread.</Description>
5-
<VersionPrefix>3.2.0</VersionPrefix>
5+
<VersionPrefix>4.0.0</VersionPrefix>
6+
<AssemblyVersion>4.0.0.0</AssemblyVersion>
67
<Authors>Serilog Contributors</Authors>
7-
<TargetFrameworks>net45;netstandard1.0;netstandard2.0</TargetFrameworks>
8+
<!-- .NET Framework version targeting is frozen at these two TFMs. -->
9+
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT'">net471;net462</TargetFrameworks>
10+
<!-- Policy is to trim TFM-specific builds to `netstandard2.0`, `net6.0`,
11+
all active LTS versions, and optionally the latest RTM version, when releasing new
12+
major Serilog versions. -->
13+
<TargetFrameworks>$(TargetFrameworks);net8.0;net6.0;netstandard2.0</TargetFrameworks>
814
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
915
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1016
<AssemblyName>Serilog.Enrichers.Thread</AssemblyName>
@@ -16,33 +22,25 @@
1622
<PackageIcon>serilog-enricher-nuget.png</PackageIcon>
1723
<PackageProjectUrl>http://serilog.net</PackageProjectUrl>
1824
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
19-
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
25+
<PackageReadmeFile>README.md</PackageReadmeFile>
26+
<PublishRepositoryUrl>true</PublishRepositoryUrl>
27+
<EmbedUntrackedSources>true</EmbedUntrackedSources>
28+
<IncludeSymbols>true</IncludeSymbols>
29+
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
2030
<LangVersion>latest</LangVersion>
2131
<Nullable>enable</Nullable>
2232
</PropertyGroup>
2333

2434
<ItemGroup>
25-
<PackageReference Include="Serilog" Version="2.9.0" />
26-
</ItemGroup>
27-
28-
<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
29-
<Reference Include="System" />
30-
<Reference Include="Microsoft.CSharp" />
35+
<PackageReference Include="Serilog" Version="4.0.0" />
3136
</ItemGroup>
3237

3338
<ItemGroup>
3439
<None Include="..\..\assets\serilog-enricher-nuget.png">
3540
<Pack>True</Pack>
3641
<PackagePath></PackagePath>
3742
</None>
43+
<None Include="../../README.md" Pack="true" Visible="false" PackagePath="/" />
3844
</ItemGroup>
3945

40-
<PropertyGroup Condition=" '$(TargetFramework)' == 'net45' ">
41-
<DefineConstants>$(DefineConstants);THREAD_NAME</DefineConstants>
42-
</PropertyGroup>
43-
44-
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
45-
<DefineConstants>$(DefineConstants);THREAD_NAME</DefineConstants>
46-
</PropertyGroup>
47-
4846
</Project>

src/Serilog.Enrichers.Thread/ThreadLoggerConfigurationExtensions.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
1615
using System;
1716
using System.Threading;
1817
using Serilog.Configuration;
@@ -39,7 +38,6 @@ public static LoggerConfiguration WithThreadId(
3938
return enrichmentConfiguration.With<ThreadIdEnricher>();
4039
}
4140

42-
#if THREAD_NAME
4341
/// <summary>
4442
/// Enrich log events with a ThreadName property containing the <see cref="Thread.CurrentThread"/> <see cref="Thread.Name"/>.
4543
/// </summary>
@@ -52,6 +50,5 @@ public static LoggerConfiguration WithThreadName(
5250
if (enrichmentConfiguration == null) throw new ArgumentNullException(nameof(enrichmentConfiguration));
5351
return enrichmentConfiguration.With<ThreadNameEnricher>();
5452
}
55-
#endif
5653
}
5754
}

0 commit comments

Comments
 (0)