Skip to content

Commit b20e71a

Browse files
committedApr 29, 2025
NLog v6 will automatic load NLog.config as before
1 parent ed598e1 commit b20e71a

File tree

2 files changed

+45
-32
lines changed

2 files changed

+45
-32
lines changed
 

‎_posts/2024-10-01-nlog-6-0-goals.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ NLog v6.0 has the following goals:
1717
- Extract NLog.Targets.NetworkTarget to its own nuget-package
1818
- Extract NLog.Targets.MailTarget to its own nuget-package
1919
- Extract NLog.Targets.FileTarget to its own nuget-package NLog.Targets.ConcurrentFileTarget
20-
- NLog will instead have a simple FileTarget without ConcurrentWrites-support but only KeepFileOpen = false
20+
- NLog will instead have a simple FileTarget without ConcurrentWrites-support, but still supports KeepFileOpen true / false
2121

2222
The overall goal for NLog v6.0 is to continue being a fully working logging-library in a single nuget-package.
2323
The NLog-package will out of the box only handle file- and console-output, which will probably cover 90 pct.

‎_posts/2025-04-01-nlog-6-0-major-changes.md

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,38 @@ layout: post
33
title: NLog 6.0 - List of major changes
44
---
55

6-
NLog 6.0 is a major version release that introduces breaking changes, including the splitting into multiple NuGet packages, and other improvements to support AOT builds.
6+
NLog 6.0 is a major version release, and introduces breaking changes to support AOT-builds by splitting into multiple nuget packages.
77

88
## Major changes
99

1010
### NLog supports AOT
1111

1212
NLog has traditionally relied on reflection to dynamically discover requirements for target output.
13-
But reflection does not always work well with build trimming, and before NLog marked itself to have trimming disabled.
13+
But reflection does not always work well with build trimming, and before NLog marked itself to be excluded from trimming.
1414

15-
NLog includes many features, each of these feature often introduce additional dependencies on the .NET library.
15+
NLog includes many features, and each feature often introduces additional dependencies on the .NET library.
1616
This can lead to overhead for AOT builds, as it must include and compile all the relevant source code.
1717

1818
NLog v6 attempts to reduce its footprint by extracting several features into separate nuget-packages:
1919

2020
- NLog.RegEx - Depends on System.Text.RegularExpressions which is a huge dependency for a logging library.
2121
- NLog.Targets.ConcurrentFile - ConcurrentWrites using global mutex from operating system API.
2222
- NLog.Targets.AtomicFile - ConcurrentWrites using atomic file-append from operating system API.
23+
- NLog.Targets.GZipFile - EnableArchiveFileCompression using GZipStream for writing GZip compressed log-files.
2324
- NLog.Targets.Mail - Depends on System.Net.Mail.SmtpClient.
24-
- NLog.Targets.Network - Depends on TCP and UDP Network Socket.
25+
- NLog.Targets.Network - Depends on TCP and UDP Network Socket, and adds support for Syslog and Graylog.
2526
- NLog.Targets.Trace - Depends on System.Diagnostics.TraceListener.
2627
- NLog.Targets.WebService - Depends on System.Net.Http.HttpClient.
2728

28-
NLog v6 also no longer supports automatic loading of `NLog.config`-file. This is because dynamic configuration
29-
loading, prevents build trimming of any NLog types, as the AOT-build cannot determine upfront what types
30-
will be used by the `NLog.config`-file.
29+
NLog v6 also no longer depends on `System.Xml.XmlReader`, but now includes its own basic XmlParser for loading `NLog.config` files.
3130

32-
### NLog without automatic loading of NLog.config
31+
NLog v6 still introduces an overhead when compared with just using `Console.WriteLine`,
32+
but now reduced to 5 MByte in comparison to 14 MBytes with NLog v5.
3333

34-
NLog will no longer automatically load the NLog LoggingConfiguration, when creating the first NLog Logger by calling `LogManger.GetCurrentClassLogger()` or `LogManger.GetLogger()`.
35-
36-
Instead one must explicit load the `NLog.config` file at application-startup:
37-
```csharp
38-
var logger = NLog.LogManager.Setup().LoadConfigurationFromFile().GetCurrentClassLogger();
39-
logger.Info("Hello World");
40-
```
41-
42-
When using Microsoft HostBuilder with `UseNLog()`, then it will continue to automatically load the NLog LoggingConfiguration without having to make any changes.
43-
44-
.NET Framework will continue to probe NLog LoggingConfiguration from the `app.config` / `web.config`, so one can consider doing this:
45-
```xml
46-
<?xml version="1.0" encoding="utf-8" ?>
47-
<configuration>
48-
<configSections>
49-
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
50-
</configSections>
51-
<nlog include="NLog.config" />
52-
</configuration>
53-
```
34+
If the `NLog.config`-file had to be explicitly loaded, then the AOT-build could trim much more,
35+
since right now the AOT-build cannot predict what types will be required by the `NLog.config`-file.
36+
But disabling automatic loading of the `NLog.config`-file is a huge breaking change,
37+
and would hurt lots of existing applications.
5438

5539
### NLog FileTarget without ConcurrentWrites
5640

@@ -71,7 +55,8 @@ The old archive-logic:
7155
- LogFile.2.txt
7256

7357
NLog FileTarget still support static archive logic with `File.Move`, but it must be explictly activated
74-
by specifying `ArchiveFileName`.
58+
by specifying `ArchiveFileName`. If not using `ArchiveFileName` but want to revert to old archive-logic
59+
with `File.Move` then just ensure to assign `ArchiveFileName="..."` with the same value as `FileName="..."`.
7560

7661
NLog FileTarget no longer has the following options:
7762

@@ -91,6 +76,18 @@ NLog FileTarget no longer has the following options:
9176
- ArchiveNumbering - Marked as obsolete. Instead use new ArchiveSuffixFormat (Rolling is unsupported).
9277

9378
If one still requires these options, then one can use the new NLog.Targets.ConcurrentFile-nuget-package.
79+
NLog.Targets.ConcurrentFile-nuget-package is the original NLog FileTarget with all its features and complexity.
80+
The goal is that NLog.Targets.ConcurrentFile-nuget-package should become legacy, but it might help some when upgrading to NLog v6.
81+
82+
Alternative options for replacing `ConcurrentWrites = true`:
83+
- Use the new nuget-package NLog.Targets.AtomicFile where AtomicFileTarget uses atomic file-appends and supports Windows / Linux with NET8.
84+
- Change to use `KeepFileOpen = false` where file is opened / closed when writing LogEvents. Recommended to use `<targets async="true">`.
85+
86+
Alternative options for replacing `EnableArchiveFileCompression = true`:
87+
- Activate NTFS compression for the logging-folder.
88+
- Setup cron-job / scheduled-task that performs ZIP-compression and cleanup of the logging-folder.
89+
- Implement background task in the application, which monitors the logging-folder and performs ZIP-compression and cleanup.
90+
- Use the new nuget-package NLog.Targets.GZipFile where GZipFileTarget writes directly to a compressed log-file using GZipStream.
9491

9592
### NLog AtomicFileTarget without mutex
9693

@@ -178,6 +175,19 @@ The `NetworkTarget` can now perform SSL handshake with custom SSL certificate fr
178175

179176
## Breaking changes
180177

178+
### Removed legacy Target-Frameworks
179+
NetStandard 1.3 and NetStandard 1.5 has now been removed, since less relevant as most have moved to NetStandard 2.0 (or newer).
180+
181+
Removes platform support for:
182+
183+
- NET CoreApp 1.0 + 1.1
184+
- UAP + UAP10.0 (UWP ver. 1)
185+
- Tizen30
186+
187+
Considering to also remove NET35 + NET45, since those Target-Frameworks requires extra effort to build when using Visual Studio 2022.
188+
Removing old Target-Frameworks will also reduce the file-size of the NLog-nuget-package.
189+
If this will break your entire eco-system then [Please tell](https://github.com/NLog/NLog/issues/4931).
190+
181191
### NLog Structured Message formatting without quotes
182192

183193
NLog v4.5 introduced support for message-templates, where it followed the Serilog approach by adding quotes around string-values:
@@ -204,7 +214,7 @@ marks the NLog `JsonLayout` `EscapeForwardSlash` as completely obsolete and no l
204214

205215
### NLog JsonLayout SuppressSpaces default true
206216

207-
The `JsonLayout` has now have a new default value for `SuppressSpaces = true`,
217+
The `JsonLayout` now have the new default value `SuppressSpaces = true`,
208218
since log-file-size / network-traffic-usage doesn't benefit from the extra spaces.
209219

210220
If the output from `JsonLayout` needs to be more human readable, then one can explictly assign
@@ -256,14 +266,17 @@ The .NET `System.Xml.XmlReader` is a heavy dependency that both loads XML using
256266
code generation to optimize serialization for types. To reduce dependencies and minimize AOT-build-filesize,
257267
then NLog now includes its own XML-parser.
258268

269+
It could have been nice if Microsoft could refactor `System.Xml.XmlReader`,
270+
so it only introduced a minimal AOT-footprint, but that is probably too late.
271+
259272
The NLog XML-parser only provides basic XML support, but it should be able to load any XML file that was
260273
working with NLog v5.
261274

262275
### NLog EventLog with more Layout
263276
Use Layout for Log + MachineName + MaxMessageLength + MaxKilobytes
264277

265278
### NLog SimpleLayout Immutable
266-
NLog `SimpleLayout` have removed the setter-method for its `Text`-property.
279+
NLog `SimpleLayout` have removed the setter-method for its `Text`-property, and is now a sealed class.
267280

268281
This is to simpilfy the NLog `SimpleLayout` API, and to make it clear that NLog will optimize based on the initial layout.
269282

0 commit comments

Comments
 (0)