Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does ASP.NET Core's built-in logging make NLog/Serilog/etc obsolete?

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)?

like image 936
grokky Avatar asked Dec 26 '16 12:12

grokky


People also ask

Which is better Serilog or NLog?

Both logging frameworks have support for a lot of different data stores. As of the writing of this post, Serilog has 81 available sinks and NLog has 82. When comparing the two, the number of sinks isn't really important, but it's a good indicator of a popular and well-supported framework.

Does Serilog work with .NET 6?

Serilog is a robust API for logging with many configurations and sinks (outputs) and it is straightforward to get started in any . NET version. With . NET 6 the way we used to configure Serilog as a logging provider in .

Does Serilog use Log4J?

Formatting. Log4Net is an add-on for Serilog to format log events as log4net or log4j compatible XML format. You can use Log4View to look at log files produced with this formatter.


2 Answers

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://docs.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.

like image 111
Julian Avatar answered Sep 27 '22 22:09

Julian


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.

like image 42
Andrius Avatar answered Sep 27 '22 22:09

Andrius