NLog 4.5 is live!
25 Mar 2018NLog 4.5 is now finally ready. NLog 5.0 beta has now been abandoned and all features has been moved to NLog 4.5.
Main features
.NET Core Support
NLog 4.5 provides official support for .NET Core without any breaking changes!
- .NET Standard 1.3 - Minimal dependencies for limited .NET Core 1 platforms (Ex. UWP1)
- .NET Standard 1.5 - Normal dependencies for standard .NET Core 1 platforms
- .NET Standard 2.0 - Normal dependencies for standard .NET Core 2 platforms
Message Template Support
Structured Logging support in NLog has been extended to also handle message templates. Joining the wave started by Serilog and Microsoft Extension Logging:
logger.Info("Order {orderid} created for {user}", 42, "Kenny");
See also How to use structured logging
JsonLayout Object Reflection Support
JsonLayout can now perform object reflection and navigate object-collections. This allows one to use anonymous object properties together with structured logging:
logger.Info("Item {shopitem} added to {orderid}", new { Id = 123, Name = "Jacket", Color = "Orange" }, 42);
Enable object reflection by configuring maxRecursionLimit
:
<layout type="JsonLayout" includeAllProperties="true" maxRecursionLimit="10"/>
Will give the following output:
{
"shopitem": {
"Id": 123,
"Name": "Jacket",
"Color": "Orange"
},
"orderid": 42
}
It is now also possible to toggle Json serialization in these selected layoutrenderers by specifying format=@
:
${event-properties:format=@}
${exception:format=@}
${gdc:format=@}
- Global Context${mdc:format=@}
- Thread Context${mdlc:format=@}
- Async Context
It is also possible to introduce your own favorite Json-Serializer by creating you own
implementation of IJsonConverter
and assign it to NLog.Config.ConfigurationItemFactory.Default.JsonConverter
.
Easier FileTarget Archive Setup
Previous NLog versions had several restrictions for how to configure FileTarget archive logic. Example if not
specifying archiveFileName
then it was very important to perform logging in an isolated folder to avoid
deleting all files.
This is no longer the case, and one can setup file archive with very few parameters:
<target type="file" logfile="hello.txt" archiveAboveSize="1000000" maxArchiveFiles="10" />
Many other improvements
For a full list of all the enhancements and performance improvements: NLog 4.5 Release Notes