Welcome to NLog!

NLog is a flexible and free logging platform for various .NET platforms, including .NET standard. NLog makes it easy to write to several targets. (console, file, database, etc.) and change the logging configuration on-the-fly.

NLog has support for structured and traditional logging.

The focus for NLog: high performance, easy-to-use, easy to extend and flexible to configure.

Features

Easy to configure

NLog is very easy to configure, both through configuration file and programmatically. Even without restarting the application, the configuration can be changed.

Output formats

NLog Layouts are available for several output formats like Simple Text, JSON, XML, CSV etc., The output can be enriched by using the many layout renders, that are able to automatically capture additional output details when logging.

Extensible

NLog already includes several targets and pre-defined layouts, but you can also extend with your own custom targets and layouts or include own custom context values

Structured logging

Full support for structured logging and handles both message-templates and custom logevent properties.

Microsoft Extension Logging

NLog can be fully integrated with Microsoft Extensible Logging (and ASP.NET Core), without it needing to replace the standard Microsoft LoggerFactory. NLog automatically captures LogEvent properties and can use them in structured logging target output.

appsettings.json

NLog configuration can be loaded from appsettings.json as an alternative to the NLog.config XML file. It is also possible to configure NLog targets using values from appsettings.json with ${configsetting}

Targets

NLog Targets handles the writing of log events to their destination, after having formatted the LogEvent using the configured NLog Layout. NLog supports sending the same LogEvent to multiple destination targets, and each target can have their own unique output format.

There are more than 30 targets provided out-of-the-box, including:

Files

Write logs to any number of files, with automatic file naming and archival.

Event Log

Write to event log local or remote

Database

Store your logs in databases supported by .NET

Console

Write real-time to the command-line console including color coding of messages

E-mail

You can send emails whenever application errors occur

Debugger output

Write to the Debugger Output Window, when debugging the application.

There are also wrapper targets which provide buffering, load balancing, failover situations, asynchronous writing and many more scenarios. The full list of targets is available on the config options page. If you didn't find the target to fit your needs, you can easily write a custom one.

Support

NLog supports the following platforms:
  • .NET 5, 6, 7 & 8 (.NET Standard 2.0)
  • .NET Framework 3.5 - 4.8
  • .NET Core 1.0 - 3.1
  • Xamarin Android + iOS (.NET Standard)
  • UWP (.NET Standard)
  • Mono 4
  • ASP.NET Core (NLog.Web.AspNetCore package)
  • ASP.NET Classic (NLog.Web package)

License

The source code is available under the terms of BSD license.