Skip to content

Commit d67c921

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

File tree

2 files changed

+8
-26
lines changed

2 files changed

+8
-26
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: 7 additions & 25 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.
@@ -25,32 +25,11 @@ NLog v6 attempts to reduce its footprint by extracting several features into sep
2525
- NLog.Targets.Trace - Depends on System.Diagnostics.TraceListener.
2626
- NLog.Targets.WebService - Depends on System.Net.Http.HttpClient.
2727

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.
28+
NLog v6 also no longer depends on `System.Xml.XmlReader`, but now includes its own basic XmlParser for loading `NLog.config` files.
3129

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

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-
```
5433

5534
### NLog FileTarget without ConcurrentWrites
5635

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

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

0 commit comments

Comments
 (0)