Skip to content

Commit 7690191

Browse files
committed
NLog v6 will automatic load NLog.config as before
1 parent ed598e1 commit 7690191

File tree

2 files changed

+14
-27
lines changed

2 files changed

+14
-27
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 can still use KeepFileOpen = 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: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ NLog 6.0 is a major version release that introduces breaking changes, including
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

1515
NLog includes many features, each of these feature often introduce 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.
@@ -20,37 +20,21 @@ NLog v6 attempts to reduce its footprint by extracting several features into sep
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 explictly 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 by default, would be a huge breaking change
37+
and would hurt lots of existing applications.
5438

5539
### NLog FileTarget without ConcurrentWrites
5640

@@ -256,6 +240,9 @@ The .NET `System.Xml.XmlReader` is a heavy dependency that both loads XML using
256240
code generation to optimize serialization for types. To reduce dependencies and minimize AOT-build-filesize,
257241
then NLog now includes its own XML-parser.
258242

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

0 commit comments

Comments
 (0)