NLog
4.7.0
NLog is a logging platform for .NET with rich log routing and management capabilities.
NLog supports traditional logging, structured logging and the combination of both.
Supported platforms:
- .NET Framework 3.5, 4, 4.5, 4.6, 4.7 & 4.8
- .NET Standard 1.3+ and 2.0+;
- .NET Framework 4 client profile
- Xamarin Android, Xamarin iOs
- UWP
- Windows Phone 8
- Silverlight 4 and 5
- Mono 4
For ASP.NET Core, check: NLog.Web.AspNetCore
See the version list below for details.
Install-Package NLog -Version 4.7.0
dotnet add package NLog --version 4.7.0
<PackageReference Include="NLog" Version="4.7.0" />
paket add NLog --version 4.7.0
Getting started with NLog
- Getting started for .NET
- Getting started for ASP.NET Core 3
- Getting started for ASP.NET Core 2
- Getting started for .NET Core 2 Console application
- Getting started for ASP.NET Core 1 (csproj - vs2017)
- How to use structured logging
- Using NLog with appsettings.json
Config
- All config options: nlog-project.org/config
Troubleshooting
Getting started with NLog
- Getting started for .NET
- Getting started for ASP.NET Core 3
- Getting started for ASP.NET Core 2
- Getting started for .NET Core 2 Console application
- Getting started for ASP.NET Core 1 (csproj - vs2017)
- How to use structured logging
- Using NLog with appsettings.json
Config
- All config options: nlog-project.org/config
Troubleshooting
Release Notes
## Bugfixes
- LogFactory - Fix deadlock issue with AutoReload (@snakefoot)
- JsonLayout - Fixed ThreadAgnostic to correctly capture context when using nested JsonLayout (@snakefoot)
- ExceptionLayoutRenderer - Fixed so Format option HResult also works for NetCore (@snakefoot)
- Log4JXml Layout - Render NDLC + NDC scopes in correct order (@adanek + @304NotModified)
- Logger - Added exception handler for CallSite capture for platform that fails to capture StackTrace (@snakefoot)
- StringSplitter - Fixed quote handling when reading elements for config list-properties (@snakefoot)
- Utilities: fix ConversionHelpers.TryParseEnum for white space (@304NotModified)
## Features
- LogManager.Setup() allows fluent configuration of LogFactory options (@snakefoot + @304NotModified)
- LogManager.Setup().SetupSerialization(s => s.RegisterObjectTransformation(...)) for overriding default property reflection (@snakefoot + @304NotModified + @Giorgi + @mmurrell)
- LogManager.Setup().SetupSerialization(s => s.RegisterConditionMethod(...)) can use lambda methods and not just static methods (@snakefoot)
- ${level:format=FullName} will expand Info + Warn to their full name (@snakefoot)
- FileTarget - Supports MaxArchiveDays for cleanup of old files based on their age (@snakefoot)
- Layout.FromMethod to create Layout directly from a lambda method (@snakefoot)
- Layout.FromString to create Layout directly from string along with optional parser validation (@snakefoot)
- ${dir-separator} for rendering platform specific directory path separator (@304NotModified)
- FileTarget - Supports ArchiveOldFileOnStartupAboveSize for cleanup of existing file when above size (@Sam13)
- InternalLogger - Added LogMessageReceived event (@304NotModified)
- DatabaseTarget - Assign connection properties like SqlConnection.AccessToken (@304NotModified + @snakefoot)
- DatabaseTarget - Assign command properties like SqlCommand.CommandTimeout (@snakefoot)
- ${onHasProperties} for only rendering when logevent includes properties from structured logging (@snakefoot)
## Improvements
- XmlLoggingConfiguration - Marked legacy constructors with ignoreErrors parameter as obsolete (@snakefoot)
- LoggingConfiguration - Perform checking of unused targets during initialization for better validation (@snakefoot)
- EventLogTarget - Improve diagnostics logging when using dynamic EventLog source (@snakefoot)
- ${longdate} now also supports raw value for use as DatabaseTarget parameter with DbType (@snakefoot)
- SourceLink for GitHub for easy debugging into the NLog source code (@304NotModified)
- JsonLayout - EscapeForwardSlash now automatically applies to sub-attributes (@snakefoot)
- TraceTarget - Introduced EnableTraceFail=false to avoid Environment.FailFast (@snakefoot)
- ExceptionLayoutRenderer - Improved error message when Format-token parsing fails (@snakefoot)
- AutoFlushWrapper - Set AutoFlush=false for AsyncTaskTarget by default (@snakefoot)
- LocalIpAddressLayoutRenderer - Higher priority to network-addresses that has valid gateway adddress (@snakefoot)
- LogFactory - Flush reports to InternalLogger what targets produces timeouts (@snakefoot)
## Performance
- ObjectGraphScanner - Avoid holding list.SyncRoot lock while scanning (@snakefoot)
- FileTarget - ConcurrentWrites=true on NetCore now much faster when archive enabled (@snakefoot)
- JsonConverter - Write DateTime directly without string allocation (@snakefoot)
- XmlLayout - Removed unnecessary double conversion to string (@snakefoot)
- WebServiceTarget - Reduced memory allocations by removing unnecessary delegate capture (@snakefoot)
- NetworkTarget - Reduced memory allocation for encoding into bytes without string allocation (@snakefoot)
- AsyncTaskTarget - Skip default AsyncWrapper since already having internal queue (@snakefoot)
- Mark Condition Expressions as ThreadSafe to improve concurrency in Layouts (@snakefoot)
- DatabaseTarget - Added IsolationLevel option that activates transactions for better batching performance (@snakefoot)
- SimpleLayout - Assignment of string-reference with null-value will translate into FixedText (@304NotModified)
- AsyncWrapper - Less aggressive with scheduling timer events for background writing (@snakefoot)
- Faster assignment of properties accessed through reflection (@304NotModified)
- ${replace} - Faster search and replace when not explicitly have requested regex support (@snakefoot)
- Skip need for Activator.CreateInstance in DbTypeSetter (@304NotModified)
Full changelog: https://github.com/NLog/NLog/blob/master/CHANGELOG.md
For all config options and platform support, check https://nlog-project.org/config/
Dependencies
-
.NETFramework 3.5
- No dependencies.
-
.NETFramework 4.0 Client
- No dependencies.
-
.NETFramework 4.5
- No dependencies.
-
.NETStandard 1.3
- Microsoft.Extensions.PlatformAbstractions (>= 1.0.0)
- NETStandard.Library (>= 1.6.0)
- System.ComponentModel.Primitives (>= 4.1.0)
- System.ComponentModel.TypeConverter (>= 4.1.0)
- System.Data.Common (>= 4.1.0)
- System.Diagnostics.StackTrace (>= 4.0.1)
- System.Net.NameResolution (>= 4.0.0)
- System.Net.Requests (>= 4.0.11)
- System.Reflection.TypeExtensions (>= 4.1.0)
- System.Xml.XmlDocument (>= 4.0.1)
-
.NETStandard 1.5
- NETStandard.Library (>= 1.6.0)
- System.ComponentModel.Primitives (>= 4.1.0)
- System.ComponentModel.TypeConverter (>= 4.1.0)
- System.Data.Common (>= 4.1.0)
- System.Diagnostics.Process (>= 4.1.0)
- System.Diagnostics.StackTrace (>= 4.0.1)
- System.Diagnostics.TraceSource (>= 4.0.0)
- System.IO.FileSystem.Watcher (>= 4.0.0)
- System.Net.NameResolution (>= 4.0.0)
- System.Net.Requests (>= 4.0.11)
- System.Reflection.TypeExtensions (>= 4.1.0)
- System.Runtime.Loader (>= 4.0.0)
- System.Threading.Thread (>= 4.0.0)
- System.Xml.XmlDocument (>= 4.0.1)
-
.NETStandard 2.0
- No dependencies.
-
MonoAndroid 4.4
- No dependencies.
-
Silverlight 4.0
- No dependencies.
-
Silverlight 5.0
- No dependencies.
-
WindowsPhone 8.0
- No dependencies.
-
Xamarin.iOS 1.0
- No dependencies.
Used By
NuGet packages (1.9K)
Showing the top 5 NuGet packages that depend on NLog:
Package | Downloads |
---|---|
NLog.Extensions.Logging
NLog LoggerProvider for Microsoft.Extensions.Logging for logging in .NET Standard libraries and .NET Core applications.
For ASP.NET Core, use NLog.Web.AspNetCore: https://www.nuget.org/packages/NLog.Web.AspNetCore
|
|
NLog.Config
NLog.config file to get started with configuring NLog.
This package is not mandatory to get started with NLog: the configuration file can
created manually (read specs here: https://github.com/NLog/NLog/wiki/Configuration-file)
or the configuration can be created programmatically. (read more here: https://github.com/NLog/NLog/wiki/Configuration-API)
Note: Unfortunately this package won't work well when using <PackageReference>
Advised to:
- download manually: https://raw.githubusercontent.com/NLog/NLog/dev/src/NuGet/NLog.Config/content/NLog.config
- set "Copy To Output Directory" to "Copy if newer"
|
|
Microsoft.ApplicationInsights.NLogTarget
Application Insights NLog Target is a custom target allowing you to send NLog log messages to Application Insights. Application Insights will collect your logs from multiple sources and provide rich powerful search capabilities. Privacy statement: https://go.microsoft.com/fwlink/?LinkId=512156
|
|
NLog.Web
NLog logging for ASP.NET and ASP.NET MVC. Includes targets and layout renderers for websites and web applications.
This package is for ASP.NET 3.5+
For ASP.NET Core: Check https://www.nuget.org/packages/NLog.Web.AspNetCore
|
|
NLog.Extended
NLog.Extended.dll provides MSMQ target and AppSetting renderer
|
GitHub repositories (239)
Showing the top 5 popular GitHub repositories that depend on NLog:
Repository | Stars |
---|---|
shadowsocks/shadowsocks-windows
If you want to keep a secret, you must also hide it from yourself.
|
|
Wox-launcher/Wox
Launcher for Windows, an alternative to Alfred and Launchy.
|
|
JustArchiNET/ArchiSteamFarm
C# application with primary purpose of idling Steam cards from multiple accounts simultaneously.
|
|
Sonarr/Sonarr
Smart PVR for newsgroup and bittorrent users.
|
|
Jackett/Jackett
API Support for your favorite torrent trackers
|
Version History
Version | Downloads | Last updated |
---|---|---|
4.7.6 | 208,469 | 12/6/2020 |
4.7.5 | 893,064 | 9/27/2020 |
4.7.4 | 980,223 | 8/22/2020 |
4.7.3 | 456,457 | 7/31/2020 |
4.7.2 | 2,676,300 | 5/18/2020 |
4.7.1 | 51,627 | 5/15/2020 |
4.7.0 | 1,909,234 | 3/20/2020 |
4.6.8 | 6,226,031 | 11/4/2019 |
4.6.7 | 5,140,947 | 8/25/2019 |
4.6.6 | 1,569,684 | 7/14/2019 |
4.6.5 | 1,999,191 | 6/14/2019 |
4.6.4 | 1,572,516 | 5/28/2019 |
4.6.3 | 1,366,187 | 4/30/2019 |
4.6.2 | 1,067,230 | 4/2/2019 |
4.6.1 | 147,189 | 3/29/2019 |
4.6.0 | 463,238 | 3/21/2019 |
4.5.11 | 6,861,079 | 11/6/2018 |
4.5.10 | 3,437,578 | 9/17/2018 |
4.5.9 | 977,319 | 8/24/2018 |
4.5.8 | 1,369,597 | 8/5/2018 |
4.5.7 | 729,757 | 7/19/2018 |
4.5.6 | 1,976,558 | 5/29/2018 |
4.5.5 | 490,574 | 5/25/2018 |
4.5.4 | 1,685,465 | 5/5/2018 |
4.5.3 | 950,932 | 4/16/2018 |
4.5.2 | 679,317 | 4/6/2018 |
4.5.1 | 205,984 | 4/3/2018 |
4.5.0 | 2,868,562 | 3/25/2018 |
4.4.13 | 558,495 | 2/27/2018 |
4.4.12 | 4,545,848 | 8/8/2017 |
4.4.11 | 1,141,338 | 6/17/2017 |
4.4.10 | 291,046 | 5/31/2017 |
4.4.9 | 766,544 | 5/5/2017 |
4.4.8 | 118,827 | 4/28/2017 |
4.4.7 | 89,313 | 4/25/2017 |
4.4.6 | 252,533 | 4/15/2017 |
4.4.5 | 351,906 | 3/28/2017 |
4.4.4 | 415,895 | 3/10/2017 |
4.4.3 | 568,846 | 2/17/2017 |
4.4.2 | 299,488 | 2/6/2017 |
4.4.1 | 869,599 | 12/24/2016 |
4.4.0 | 234,190 | 12/14/2016 |
4.3.11 | 789,311 | 11/7/2016 |
4.3.10 | 528,308 | 10/11/2016 |
4.3.9 | 391,754 | 9/18/2016 |
4.3.8 | 507,865 | 9/5/2016 |
4.3.7 | 477,134 | 8/6/2016 |
4.3.6 | 219,086 | 7/23/2016 |
4.3.5 | 703,374 | 6/12/2016 |
4.3.4 | 602,636 | 5/16/2016 |
4.3.3 | 294,782 | 4/28/2016 |
4.3.2 | 73,968 | 4/26/2016 |
4.3.1 | 92,427 | 4/20/2016 |
4.3.0 | 101,142 | 4/16/2016 |
4.2.3 | 1,198,419 | 12/20/2015 |
4.2.2 | 228,747 | 12/2/2015 |
4.2.1 | 213,902 | 11/21/2015 |
4.2.0 | 319,856 | 10/24/2015 |
4.1.2 | 576,675 | 9/20/2015 |
4.1.1 | 115,926 | 9/12/2015 |
4.1.0 | 161,291 | 8/31/2015 |
4.0.1 | 598,961 | 6/18/2015 |
4.0.0 | 639,299 | 6/9/2015 |
3.2.1 | 640,085 | 4/24/2015 |
3.2.0 | 1,119,833 | 1/2/2015 |
3.1.0 | 1,152,271 | 6/24/2014 |
3.0.0 | 180,224 | 6/2/2014 |
2.1.0 | 1,020,138 | 10/10/2013 |
2.0.1.2 | 628,869 | 4/8/2013 |
2.0.0.2000 | 1,059,093 | 7/18/2011 |
1.0.0.505 | 219,853 | 1/7/2011 |