Skip to content

Commit 45fc724

Browse files
committed
NLog v6 - Rc1 (Nullable references and ReadOnlySpan)
1 parent 8fd9fb0 commit 45fc724

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

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

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,23 @@ await using var logFactory = NLog.LogManager.Setup().LoadConfigurationFromFile()
131131
The NLog LogFactory `Dispose()`-method has been changed to skip flush with help from worker-threads,
132132
but will only perform synchronous NLog Target Close.
133133

134+
### NLog API with nullable references
135+
NLog API has been updated to enable nullable, and has been compiled using C# v9 for all target-platforms.
136+
137+
NET3 introduced C# v8 with support for nullable reference types, that allows static analysis to avoid
138+
NullReferenceException (NRE). NET5 introduced C# v9 with improved support for nullable generics.
139+
140+
This will improve the user-experience, when using the NLog API directly instead of NLog configuration files.
141+
142+
### NLog Logger API with ReadOnlySpan
143+
NLog Logger now supports `params ReadOnlySpan` and can skip `params object[]`-allocation, when many parameters
144+
and LogLevel is not enabled.
145+
146+
NET9 introduced C# v13 that introduced `params ReadOnlySpan`, which is now supported by NLog for NetStandard2.1.
147+
148+
NLog extends the optimization to completely skip the `params object[]`-allocation, when using message-templates
149+
and it is not possible to defer the parsing of the message-template on background thread.
150+
134151
### NLog GelfTarget and GelfLayout
135152

136153
The [NLog.Targets.Network](https://www.nuget.org/packages/NLog.Targets.Network) nuget-package also includes support for the Graylog Extended Log Format (GELF).
@@ -148,7 +165,7 @@ custom property-names with underscore `_`.
148165

149166
<targets async="true">
150167
<target xsi:type="Gelf" name="GelfTcp" address="tcp://localhost:12200" newLine="true" lineEnding="Null">
151-
<GelfField name="MyPropertyName" layout="MyPropertyValue" />
168+
<GelfField name="ThreadId" layout="${ThreadId}" />
152169
</target>
153170
</targets>
154171

@@ -183,7 +200,7 @@ The `SyslogLayout` supports both RFC-3164 (simple) + RFC-5424 (structured) loggi
183200
<target xsi:type="SysLog" name="SyslogTcp" address="tcp://localhost:514">
184201
<Rfc3164>false</Rfc3164>
185202
<Rfc5424>true</Rfc5424>
186-
<StructuredDataParam name="MyPropertyName" layout="MyPropertyValue" />
203+
<StructuredDataParam name="ThreadId" layout="${ThreadId}" />
187204
</target>
188205
</targets>
189206

@@ -329,32 +346,11 @@ but that is probably too late.
329346
The NLog XML-parser only provides basic XML support, but it should be able to load any XML file that was
330347
working with NLog v5.
331348

332-
### NLog EventLog with more Layout
333-
Use Layout for Log + MachineName + MaxMessageLength + MaxKilobytes
334-
335349
### NLog SimpleLayout Immutable
336350
NLog `SimpleLayout` have removed the setter-method for its `Text`-property, and is now a sealed class.
337351

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

340-
### Minimal Logger-API
341-
Not ready yet, and post-poned because major breaking change, which makes it harder to test first NLog v6-Preview.
342-
343-
### Logger API with string interpolation
344-
Not ready yet, and post-poned because waiting for minimal Logger-API
345-
346-
Idea is to skip string interpolation, when LogLevel is not enabled.
347-
348-
### Logger API with ReadOnlySpan params
349-
Not ready yet, and post-poned because waiting for minimal Logger-API
350-
351-
Idea is to skip params array-allocation, when LogLevel is not enabled.
352-
353-
And if structured-logging then skip params allocation, but only rely on properties-dictionary.
354-
355-
### NLog Nullable References
356-
Not ready yet, and post-poned because waiting for minimal Logger-API
357-
358354
## Many other improvements
359355

360356
For full list of all changes: [NLog 6.0 Pull Requests](https://github.com/NLog/NLog/pulls?q=is%3Apr+is%3Amerged+milestone:%226.0%22)

0 commit comments

Comments
 (0)