Skip to content

Commit e596d64

Browse files
authored
NLog v6 RC2 (#784)
1 parent 5caec9d commit e596d64

27 files changed

+510
-475
lines changed

CHANGELOG.MD

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

33
Date format: (year/month/day)
44

5+
### Version 6.0 RC2 (2025/06/02)
6+
7+
- Updated to NLog v6.0-RC2
8+
- Removed support for NetStandard 1.3 + 1.5
9+
- Enabled nullable references
10+
- Avoid boxing when extracting LogEvent properties from struct
11+
- Reduce allocation when creating LogEvent with properties by using ReadOnlySpan
12+
- Enabled <IsAotCompatible>
13+
14+
List of major changes in NLog 6.0: https://nlog-project.org/2025/04/29/nlog-6-0-major-changes.html
15+
516
### Version 5.5 (2025/05/29)
617

718
**Improvements**

build.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# creates NuGet package at \artifacts
33
dotnet --version
44

5-
$versionPrefix = "5.5.0"
6-
$versionSuffix = ""
5+
$versionPrefix = "6.0.0"
6+
$versionSuffix = "rc2"
77
$versionFile = $versionPrefix + "." + ${env:APPVEYOR_BUILD_NUMBER}
88
$versionProduct = $versionPrefix;
99

@@ -26,7 +26,7 @@ if (-Not $LastExitCode -eq 0) {
2626
exit $LastExitCode
2727
}
2828

29-
msbuild /t:Pack .\src\NLog.Extensions.Logging\ /p:targetFrameworks='"net461;netstandard1.3;netstandard1.5;netstandard2.0;netstandard2.1;net6.0;net8.0"' /p:VersionPrefix=$versionPrefix /p:VersionSuffix=$versionSuffix /p:FileVersion=$versionFile /p:ProductVersion=$versionProduct /p:Configuration=Release /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg /p:PackageOutputPath=..\..\artifacts /verbosity:minimal /p:ContinuousIntegrationBuild=true
29+
msbuild /t:Pack .\src\NLog.Extensions.Logging\ /p:targetFrameworks='"net461;netstandard2.0;netstandard2.1;net6.0;net8.0"' /p:VersionPrefix=$versionPrefix /p:VersionSuffix=$versionSuffix /p:FileVersion=$versionFile /p:ProductVersion=$versionProduct /p:Configuration=Release /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg /p:PackageOutputPath=..\..\artifacts /verbosity:minimal /p:ContinuousIntegrationBuild=true
3030
if (-Not $LastExitCode -eq 0) {
3131
exit $LastExitCode
3232
}

examples/NetCore2/ConsoleExample/nlog.config

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8" ?>
2-
<!-- XSD manual extracted from package NLog.Schema: https://www.nuget.org/packages/NLog.Schema-->
3-
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xsi:schemaLocation="NLog NLog.xsd"
2+
<!-- Local NLog.XSD from nuget-package NLog.Schema -->
3+
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
4+
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
45
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
56
autoReload="true"
67
internalLogFile="c:\temp\console-example-internal.log"

examples/NetCore2/HostingExample/nlog.config

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8" ?>
2-
<!-- XSD manual extracted from package NLog.Schema: https://www.nuget.org/packages/NLog.Schema-->
3-
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xsi:schemaLocation="NLog NLog.xsd"
2+
<!-- Local NLog.XSD from nuget-package NLog.Schema -->
3+
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
4+
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
45
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
56
autoReload="true"
67
internalLogFile="c:\temp\console-example-internal.log"

src/NLog.Extensions.Hosting/Extensions/ConfigureExtensions.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.IO;
3-
using System.Reflection;
43
using Microsoft.Extensions.Configuration;
54
using Microsoft.Extensions.DependencyInjection;
65
using Microsoft.Extensions.Hosting;
@@ -34,7 +33,7 @@ public static IHostBuilder UseNLog(this IHostBuilder builder)
3433
/// <param name="builder"></param>
3534
/// <param name="options">NLogProviderOptions object to configure NLog behavior</param>
3635
/// <returns>IHostBuilder for chaining</returns>
37-
public static IHostBuilder UseNLog(this IHostBuilder builder, NLogProviderOptions options)
36+
public static IHostBuilder UseNLog(this IHostBuilder builder, NLogProviderOptions? options)
3837
{
3938
Guard.ThrowIfNull(builder);
4039
#if NETSTANDARD2_0
@@ -89,7 +88,7 @@ public static IHostApplicationBuilder UseNLog(this IHostApplicationBuilder build
8988
/// <param name="builder"></param>
9089
/// <param name="options">NLogProviderOptions object to configure NLog behavior</param>
9190
/// <returns>IHostApplicationBuilder for chaining</returns>
92-
public static IHostApplicationBuilder UseNLog(this IHostApplicationBuilder builder, NLogProviderOptions options)
91+
public static IHostApplicationBuilder UseNLog(this IHostApplicationBuilder builder, NLogProviderOptions? options)
9392
{
9493
Guard.ThrowIfNull(builder);
9594
builder.Services.TryAddNLogLoggingProvider((svc, addlogging) => svc.AddLogging(addlogging), builder.Configuration, options, (serviceProvider, config, opt) => CreateNLogLoggerProvider(serviceProvider, config, builder.Environment, opt));
@@ -119,31 +118,33 @@ public static IHostApplicationBuilder UseNLog(this IHostApplicationBuilder build
119118
}
120119
#endif
121120

122-
private static void AddNLogLoggerProvider(IServiceCollection services, IConfiguration hostConfiguration, IHostEnvironment hostEnvironment, NLogProviderOptions options, Func<IServiceProvider, IConfiguration, IHostEnvironment, NLogProviderOptions, NLogLoggerProvider> factory)
121+
private static void AddNLogLoggerProvider(IServiceCollection services, IConfiguration? hostConfiguration, IHostEnvironment? hostEnvironment, NLogProviderOptions? options, Func<IServiceProvider, IConfiguration?, IHostEnvironment?, NLogProviderOptions, NLogLoggerProvider> factory)
123122
{
124123
services.TryAddNLogLoggingProvider((svc, addlogging) => svc.AddLogging(addlogging), hostConfiguration, options, (provider, cfg, opt) => factory(provider, cfg, hostEnvironment, opt));
125124
}
126125

127-
private static NLogLoggerProvider CreateNLogLoggerProvider(IServiceProvider serviceProvider, IConfiguration hostConfiguration, IHostEnvironment hostEnvironment, NLogProviderOptions options)
126+
private static NLogLoggerProvider CreateNLogLoggerProvider(IServiceProvider serviceProvider, IConfiguration? hostConfiguration, IHostEnvironment? hostEnvironment, NLogProviderOptions options)
128127
{
129128
return serviceProvider.CreateNLogLoggerProvider(hostConfiguration, options, LogManager.LogFactory);
130129
}
131130

132-
private static NLogLoggerProvider CreateNLogLoggerProvider(IServiceProvider serviceProvider, IConfiguration hostConfiguration, IHostEnvironment hostEnvironment, NLogProviderOptions options, LogFactory logFactory)
131+
private static NLogLoggerProvider CreateNLogLoggerProvider(IServiceProvider serviceProvider, IConfiguration? hostConfiguration, IHostEnvironment? hostEnvironment, NLogProviderOptions options, LogFactory logFactory)
133132
{
134133
NLogLoggerProvider provider = serviceProvider.CreateNLogLoggerProvider(hostConfiguration, options, logFactory);
135134

136135
string nlogConfigFile = string.Empty;
137-
string contentRootPath = hostEnvironment?.ContentRootPath;
138-
string environmentName = hostEnvironment?.EnvironmentName;
136+
var contentRootPath = hostEnvironment?.ContentRootPath;
137+
var environmentName = hostEnvironment?.EnvironmentName;
139138
if (!string.IsNullOrWhiteSpace(contentRootPath) || !string.IsNullOrWhiteSpace(environmentName))
140139
{
141140
provider.LogFactory.Setup().LoadConfiguration(cfg =>
142141
{
143142
if (!IsLoggingConfigurationLoaded(cfg.Configuration))
144143
{
145144
nlogConfigFile = ResolveEnvironmentNLogConfigFile(contentRootPath, environmentName);
145+
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
146146
cfg.Configuration = null;
147+
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type.
147148
}
148149
});
149150
}
@@ -157,7 +158,7 @@ private static NLogLoggerProvider CreateNLogLoggerProvider(IServiceProvider serv
157158
return provider;
158159
}
159160

160-
private static string ResolveEnvironmentNLogConfigFile(string basePath, string environmentName)
161+
private static string ResolveEnvironmentNLogConfigFile(string? basePath, string? environmentName)
161162
{
162163
if (!string.IsNullOrWhiteSpace(basePath))
163164
{
@@ -182,7 +183,7 @@ private static string ResolveEnvironmentNLogConfigFile(string basePath, string e
182183
if (!string.IsNullOrWhiteSpace(environmentName))
183184
return $"nlog.{environmentName}.config";
184185

185-
return null;
186+
return string.Empty;
186187
}
187188

188189
private static bool IsLoggingConfigurationLoaded(LoggingConfiguration cfg)

src/NLog.Extensions.Hosting/ILLink.Descriptors.xml

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

src/NLog.Extensions.Hosting/NLog.Extensions.Hosting.csproj

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
<PropertyGroup>
44
<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0;net8.0</TargetFrameworks>
55
<DebugType Condition=" '$(Configuration)' == 'Debug' ">Full</DebugType>
6-
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
7-
<GenerateDocumentationFile>true</GenerateDocumentationFile>
86

97
<Product>NLog.Extensions.Hosting v$(ProductVersion)</Product>
108
<InformationalVersion>$(ProductVersion)</InformationalVersion>
@@ -31,14 +29,18 @@ For ASP.NET Core, check: https://www.nuget.org/packages/NLog.Web.AspNetCore
3129
<!-- SonarQube needs ProjectGuid -->
3230
<ProjectGuid>{548E65CE-0378-4812-AE00-B173F1251D3C}</ProjectGuid>
3331
<SignAssembly>true</SignAssembly>
34-
<AssemblyVersion>5.0.0.0</AssemblyVersion>
32+
<AssemblyVersion>6.0.0.0</AssemblyVersion>
3533
<AssemblyOriginatorKeyFile>..\NLog.snk</AssemblyOriginatorKeyFile>
3634
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
3735
<LangVersion>latest</LangVersion>
3836
<!-- EmbedUntrackedSources for deterministic build -->
39-
<EmbedUntrackedSources>true</EmbedUntrackedSources>
37+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
38+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
39+
<Nullable>enable</Nullable>
40+
<LangVersion>9</LangVersion>
4041
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
41-
<IsTrimmable>true</IsTrimmable>
42+
<IsTrimmable Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">true</IsTrimmable>
43+
<IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))">true</IsAotCompatible>
4244
</PropertyGroup>
4345

4446
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
@@ -67,12 +69,6 @@ For ASP.NET Core, check: https://www.nuget.org/packages/NLog.Web.AspNetCore
6769
<ProjectReference Include="..\NLog.Extensions.Logging\NLog.Extensions.Logging.csproj" />
6870
</ItemGroup>
6971

70-
<ItemGroup>
71-
<EmbeddedResource Include="ILLink.Descriptors.xml">
72-
<LogicalName>ILLink.Descriptors.xml</LogicalName>
73-
</EmbeddedResource>
74-
</ItemGroup>
75-
7672
<ItemGroup>
7773
<None Include="N.png" Pack="true" PackagePath="" Visible="false" />
7874
<None Include="README.md" Pack="true" PackagePath="" />

0 commit comments

Comments
 (0)