Skip to content

Commit 4d0e624

Browse files
authored
Merge pull request #26 from nkz-soft/net8.0-and-net9.0
Support net8.0 and net9.0
2 parents 52f021a + fefa443 commit 4d0e624

File tree

8 files changed

+73
-34
lines changed

8 files changed

+73
-34
lines changed

.github/workflows/build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- name: Setup .NET SDK
2525
uses: actions/setup-dotnet@v4
2626
with:
27-
dotnet-version: 8.0.x
27+
dotnet-version: 9.0.x
2828
- name: Build
2929
run: dotnet build -c Release
3030
- name: Test

.github/workflows/publish-nuget.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: Setup .NET SDK
1616
uses: actions/setup-dotnet@v4
1717
with:
18-
dotnet-version: 8.0.x
18+
dotnet-version: 9.0.x
1919
- name: Build
2020
run: dotnet build -c Release
2121
- name: Test

Directory.Build.props

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
<Project>
22
<PropertyGroup>
3+
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
34
<LangVersion>latest</LangVersion>
5+
<ImplicitUsings>enable</ImplicitUsings>
46
<Nullable>enable</Nullable>
57
<EnableNETAnalyzers>true</EnableNETAnalyzers>
68
<AnalysisLevel>latest</AnalysisLevel>
7-
<Features>strict</Features>
8-
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
9-
<ImplicitUsings>enable</ImplicitUsings>
9+
<Features>strict</Features>
10+
<RunAnalyzersDuringBuild>true</RunAnalyzersDuringBuild>
11+
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
12+
<CodeAnalysisTreatWarningsAsErrors>false</CodeAnalysisTreatWarningsAsErrors>
13+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
14+
<AnalysisLevel>latest-Recommended</AnalysisLevel>
15+
<AnalysisMode>Recommended</AnalysisMode>
16+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1017
</PropertyGroup>
1118

1219
<PropertyGroup>
@@ -23,8 +30,20 @@
2330
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
2431
</PropertyGroup>
2532

33+
<PropertyGroup>
34+
<NoWarn>$(NoWarn);MA0165;AV1500</NoWarn>
35+
</PropertyGroup>
36+
2637
<ItemGroup>
27-
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All"/>
38+
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All"/>
39+
<PackageReference Include="Meziantou.Analyzer" PrivateAssets="All"/>
40+
<PackageReference Include="Roslynator.Analyzers" PrivateAssets="All"/>
41+
<PackageReference Include="Roslynator.CodeAnalysis.Analyzers" PrivateAssets="All"/>
42+
<PackageReference Include="Roslynator.Formatting.Analyzers" PrivateAssets="All"/>
43+
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" PrivateAssets="All"/>
44+
<PackageReference Include="AsyncAwaitBestPractices" PrivateAssets="All"/>
45+
<PackageReference Include="SerilogAnalyzer" PrivateAssets="All"/>
46+
<PackageReference Include="CSharpGuidelinesAnalyzer" PrivateAssets="All"/>
2847
</ItemGroup>
2948

3049
</Project>

Directory.Packages.props

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Project>
2+
<PropertyGroup>
3+
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
4+
</PropertyGroup>
5+
<ItemGroup>
6+
<PackageVersion Include="Serilog" Version="4.2.0" />
7+
<PackageVersion Include="Serilog.Enrichers.CorrelationId" Version="3.0.1" />
8+
<PackageVersion Include="Serilog.Enrichers.Sensitive" Version="1.7.3" />
9+
<PackageVersion Include="Serilog.Extensions.Logging" Version="9.0.1" />
10+
<PackageVersion Include="Serilog.Sinks.Console" Version="6.0.0" />
11+
<PackageVersion Include="Serilog.Sinks.File" Version="6.0.0" />
12+
<PackageVersion Include="Serilog.Settings.Configuration" Version="9.0.0" />
13+
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
14+
<PackageVersion Include="Meziantou.Analyzer" Version="2.0.196" />
15+
<PackageVersion Include="Roslynator.Analyzers" Version="4.13.1" />
16+
<PackageVersion Include="Roslynator.CodeAnalysis.Analyzers" Version="4.13.1" />
17+
<PackageVersion Include="Roslynator.Formatting.Analyzers" Version="4.13.1" />
18+
<PackageVersion Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.13.61" />
19+
<PackageVersion Include="AsyncAwaitBestPractices" Version="9.0.0" />
20+
<PackageVersion Include="SerilogAnalyzer" Version="0.15.0" />
21+
<PackageVersion Include="CSharpGuidelinesAnalyzer" Version="3.8.5" />
22+
</ItemGroup>
23+
</Project>

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "8.0.0",
3+
"version": "9.0.0",
44
"rollForward": "latestMinor",
55
"allowPrerelease": true
66
}

src/NKZSoft.Service.Configuration.Logger/Constants.cs

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
54
<RepositoryUrl>https://github.com/nkz-soft/NKZSoft.Service.Configuration.Logger</RepositoryUrl>
6-
<Version>1.3.2</Version>
5+
<Version>2.0.0</Version>
76
<Description>Provides the configuration for Serilog</Description>
8-
<Copyright>Copyright © 2024</Copyright>
7+
<Copyright>Copyright© 2025</Copyright>
98
</PropertyGroup>
109

1110
<ItemGroup>
12-
<PackageReference Include="Serilog" Version="4.2.0" />
13-
<PackageReference Include="Serilog.Enrichers.CorrelationId" Version="3.0.1" />
14-
<PackageReference Include="Serilog.Enrichers.Sensitive" Version="1.7.3" />
15-
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
16-
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
17-
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
18-
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.4" />
19-
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="8.0.0" />
11+
<PackageReference Include="Serilog" />
12+
<PackageReference Include="Serilog.Enrichers.CorrelationId" />
13+
<PackageReference Include="Serilog.Enrichers.Sensitive" />
14+
<PackageReference Include="Serilog.Extensions.Logging" />
15+
<PackageReference Include="Serilog.Sinks.Console" />
16+
<PackageReference Include="Serilog.Sinks.File" />
17+
<PackageReference Include="Serilog.Settings.Configuration" />
18+
<PackageReference Update="Microsoft.SourceLink.GitHub" />
2019
</ItemGroup>
2120

2221
</Project>

src/NKZSoft.Service.Configuration.Logger/ServiceCollectionExtensions.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
namespace NKZSoft.Service.Configuration.Logger;
22

3+
/// <summary>
4+
/// Extension methods for <see cref="IServiceCollection"/>
5+
/// </summary>
36
public static class ServiceCollectionExtensions
47
{
58
private const string MicroserviceNameProperty = "MicroserviceName";
9+
private const string CorrelationId = "X-Correlation-Id";
610

711
/// <summary>
812
/// Add Serilog to the logging pipeline.
@@ -15,24 +19,27 @@ public static IServiceCollection AddLogging(this IServiceCollection services, IC
1519
ArgumentNullException.ThrowIfNull(services);
1620
ArgumentNullException.ThrowIfNull(configuration);
1721

18-
var serviceName = Assembly.GetCallingAssembly().GetName().Name!;
22+
var serviceName = Assembly.GetCallingAssembly().GetName().Name;
1923

2024
services.AddLogging(loggingBuilder =>
2125
loggingBuilder.AddSerilog(dispose: true));
2226

2327
var logger = new LoggerConfiguration()
2428
.ReadFrom.Configuration(configuration)
25-
.Enrich.WithProperty(MicroserviceNameProperty, serviceName, true)
29+
.Enrich.WithProperty(MicroserviceNameProperty, serviceName, destructureObjects: true)
2630
.Enrich.FromLogContext()
27-
.Enrich.WithCorrelationIdHeader(Constants.Headers.CorrelationId)
28-
.WriteTo.Console(formatProvider:CultureInfo.InvariantCulture)
31+
.Enrich.WithCorrelationIdHeader(CorrelationId)
32+
.WriteTo.Console(formatProvider: CultureInfo.InvariantCulture)
2933
.CreateLogger();
3034

3135
Log.Logger = logger;
3236

33-
var loggerFactory = new LoggerFactory();
34-
loggerFactory.AddSerilog(logger);
35-
services.AddSingleton<ILoggerFactory>(loggerFactory);
37+
services.AddSingleton<ILoggerFactory>(_ =>
38+
{
39+
var factory = new LoggerFactory();
40+
factory.AddSerilog(logger);
41+
return factory;
42+
});
3643

3744
return services;
3845
}

0 commit comments

Comments
 (0)