Skip to content

Commit 2b24b99

Browse files
committed
NLog v6 - Rc1 (RequiredParameter + ForceWriteLine)
1 parent c7e4036 commit 2b24b99

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

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

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,37 @@ The `NetworkTarget` now recognizes these new settings:
255255

256256
The `NetworkTarget` can now perform SSL handshake with custom SSL certificate from file, without needing to register the certificate in the global operating-system cache.
257257

258+
### NLog.Schema for more intellisense
259+
260+
The [NLog.Schema](https://www.nuget.org/packages/NLog.Schema/) nuget-package now includes copy of NLog.xsd XML schema file to local project folder.
261+
262+
The NLog.Schema-nuget-package has been updated to also include Intellisense for NLog Targets / Layouts outside the default NLog-nuget-package.
263+
264+
When adding the NLog.Schema-nuget-package to the application-project that includes `NLog.config` XML-file, then Intellisense will work with this:
265+
```xml
266+
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
267+
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd">
268+
<!-- configuration goes here -->
269+
</nlog>
270+
```
271+
272+
Alternative one can enable "Automatically download DTDs and schemas" (Visual Studio Options), then Intellisense works with using direct URL:
273+
```xml
274+
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
275+
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd http://www.nlog-project.org/schemas/NLog.xsd">
276+
<!-- configuration goes here -->
277+
</nlog>
278+
```
279+
280+
Notice Intellisense will only work in Visual Studio when using `xsi:type="..."`:
281+
```xml
282+
<target xsi:type="TypeName"/>
283+
```
284+
And not:
285+
```xml
286+
<target type="TypeName"/>
287+
```
288+
258289
## Breaking changes
259290

260291
### Removed legacy Target-Frameworks
@@ -287,6 +318,20 @@ It is possible to globally revert to old behavior:
287318
LogManager.Setup().SetupSerialization(s => s.RegisterValueFormatterWithStringQuotes());
288319
```
289320

321+
### NLog Console without WriteLine
322+
The Console for an application is usually a singleton, and there is an overhead for every write-operation.
323+
The normal work-around is to send output to a queue, and let a background thread do the actual Console writing.
324+
But if the application threads are running at full speed, then they can easily produce more output than the background thread can handle.
325+
326+
NLog has the ability to batch multiple LogEvents into a single write-operation, when combining the NLog ConsoleTarget with
327+
AsyncWrapperTarget (Ex. `<targets async="true">`). When enabled then it would double the performance of the Console-output.
328+
This ability was introduced with NLog v4.6.8 and protected with the feature-flag `WriteBuffer`.
329+
330+
NLog v6 enables this feature and will not use Console.WriteLine by default.
331+
The feature-flag has also changed name to `ForceWriteLine` (Default = false).
332+
If depending on console redirection where output must reach `Console.WriteLine`,
333+
then one can explicit assign `ForceWriteLine = true` for the NLog ConsoleTarget.
334+
290335
### NLog JsonLayout EscapeForwardSlash obsolete
291336

292337
NLog v5 changed `JsonLayout` to have the default value `EscapeForwardSlash = false`, and now NLog v6
@@ -340,6 +385,25 @@ If it is important to redirect NLog InternalLogger output to `System.Diagnostics
340385
then one can use NLog `InternalLogger.LogWriter` to assign a custom `StringWriter` that performs the forwarding.
341386
Alternative one can setup custom subscriber to NLog `InternalLogger.InternalEventOccurred` event handler.
342387

388+
### NLog RequiredParameter attribute ignored
389+
390+
NLog have removed its validation of properties marked with `[RequiredParameter]`, where it would alert
391+
when Target- or Layout-options was missing a value. NLog have now changed to nullable references,
392+
so options that must have a value are not nullable and always have a value.
393+
394+
This means that authors of NLog Targets or Layouts should not rely on `[RequiredParameter]`,
395+
but should instead perform their own validation of options during initialization. Ex:
396+
397+
```csharp
398+
protected override void InitializeTarget()
399+
{
400+
base.InitializeTarget();
401+
402+
if (FileName is null || ReferenceEquals(FileName, Layout.Empty))
403+
throw new NLogConfigurationException("FileTarget FileName-property must be assigned.");
404+
}
405+
```
406+
343407
### NLog XmlParser replaces XmlReader
344408

345409
The .NET `System.Xml.XmlReader` is a heavy dependency that depend on HttpClient for loading external XML,

0 commit comments

Comments
 (0)