13

We use NLog or Serilog to do logging. We're busy porting a system from ASP.NET to ASP.NET Core, which has logging built in.

Ideally, we'd like to drop NLog, as there doesn't appear to be a need for it anymore.

However, is the built in logging equivalent to NLog? Is it missing any major features? Is there any point in continuing using NLog (or something similar e.g. Serilog)?

Julian
  • 33,915
  • 22
  • 119
  • 174
grokky
  • 8,537
  • 20
  • 62
  • 96

2 Answers2

11

The ASP.NET logging is a common (logging) interface and log implementation.

You could use the common interface and 3rd party library (e.g NLog) together as the infrastructure is prepared for that.

If you take NLog over the built-in logging implementation you win:

  • changing configuration on-the-fly (while running application without restart)
  • more targets (e.g. database, file). There is no file target in the built-in: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/logging. The mail target in NLog isn't in .NET Standard yet, but it's planned. The mail target is there for .NET Standard 2 and for .NET Standard 1 there is NLog.MailKit
  • more options in targets (e.g. file archiving)
  • writing extra context info, like ${processid}
  • as we invest a lot of in performance optimization, I would expect performance.
  • async logging - which isn't in ASP.NET logging as far as I know.
  • advanced features like buffering, fallbacks & limiting your logs, filter conditions with context info, writing concurrent to one file etc.
  • NLog is easier to extend (not only targets but also layout renderers, layouts etc.)
  • possibility for structural logging (Serilog, NLog 4.5)

But as always, if you don't need these features then maybe less (libraries) is more.

Julian
  • 33,915
  • 22
  • 119
  • 174
  • Is async logging missing from NLog or from ASP.NET Core? – grokky Dec 26 '16 at 13:11
  • Aspnet core. Rephrased it :) – Julian Dec 26 '16 at 14:22
  • Regarding "changing configuration on-the-fly (while running application without restart)" --> some of ASP.NET Core's loggers support this as well! But NLog is definitely way fancier overall! – Eilon Jan 01 '17 at 21:08
  • @Eilon Do you mean Serilog or without 3th party library? – Julian Jan 01 '17 at 21:25
  • @Julian without 3rd party libs. Check out the two files from default ASP.NET Core template here: https://github.com/aspnet/Templates/tree/dev/src/Rules/StarterWeb/IndividualAuth . In Startup.cs you can see `reloadOnChange: true` and later down it passes the config object to `AddConsole`. If you change `appsettings.json` the logger will reload settings. – Eilon Jan 02 '17 at 03:26
8

I wouldn't say that ASP.NET Core's logging API makes NLog and other providers obsolete. What ASP.NET Core provides is a nice abstraction so logging frameworks can be switched without changing code that depends on logging.

Nlog still provides useful configuration features that are not implemented in ASP.NET Core logging API.

Andrius
  • 2,247
  • 3
  • 14
  • 15
  • Yes NLog's config via xml file is useful. Can be easily done in ASP.NET Core config framework though. I wonder whether it's a good enough reason to keep NLog. – grokky Dec 26 '16 at 12:42
  • Well then I guess it solely depends on you requirements. If ASP.NET logging API is enough for you - use it. Keep in mind that if you want to log to text file, not only to console, you will have to use some logging provider. Serilog has a simple configuration for forwarding logs to text file. – Andrius Dec 26 '16 at 12:51
  • 1
    Didn't realise it [doesn't log to disk](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/logging#built-in-logging-providers). That's a major missing feature! – grokky Dec 26 '16 at 13:08