Is there a logging facade for the .NET world?

后端 未结 7 712
情深已故
情深已故 2020-12-13 06:17

I\'m somewhat new to the .NET stack and I was wondering if there is an equivalent to slf4j for the .NET platform. For me, logging to a Facade and being able to swap out logg

相关标签:
7条回答
  • 2020-12-13 06:35

    Update for .NET Core:

    • LibLog - https://github.com/damianh/LibLog - embedded logging facade, source code nuget package which is embedded into your project. Automatically detects and uses NLog, log4net, Serilog, LoupeLog

    • Microsoft: Microsoft.Extensions.Logging.Abstractions - https://github.com/aspnet/Logging. .NETCore supported

    • Common Logging - https://github.com/net-commons/common-logging. .NETCore supported since 3.4.1, not under active development

    0 讨论(0)
  • 2020-12-13 06:41

    I had the same Problem. After going through those recommended above, I discovered Ninject.Extensions.Logging

    Which is great since a facade makes best sense in combination with DI anyway

    It comes with proxies for NLog, NLog2 & log4net.

    Here is a nice example on how to use it in combination with NLog: http://blog.tonysneed.com/2011/10/09/using-nlog-with-dependency-injection/

    I understand, that this question is already a couple of years old, but due to completeness for other users, I still chose to post this 'Solution'

    0 讨论(0)
  • 2020-12-13 06:41

    I somehow found all solutions in here unsatisfying, especially for libraries/APIs. Although I never thought I would, I actually wrote an Open Source "logger" which should handle most concerns.

    Maybe you can have a look at Dapplo.Log, you can get it from NuGet.

    The idea is to use Dapplo.Log in your library, and the project which uses this can than direct (when needed) any log output to their logger of choice. Examples for directing the output can be found in the tests, with implementations of some major frameworks here.

    It's probably not perfect (yet), and I welcome pull-requests or tickets.

    0 讨论(0)
  • 2020-12-13 06:50

    Since this was written another interesting logging wrapper called Fody.Anotar has appeared. As of today, it's probably the most complete of all of them. Most of the other, but Logging Faciliy, are quite outdated, supporting only the oldest loggers.

    It has adapters for NLog, Log4Net, Serilog, CommongLogging, Catel, LibLog, MetroLog, NServiceBus and Splat, and allows you to create an adapter for your own library.

    You can use Nuget to install it. Look for Anotar.*.Fody packages, for example Anotar.NLog.Fody.

    0 讨论(0)
  • 2020-12-13 06:52

    Excuse I used this thing and I forgot it wasn't the Apache version. It's actually open-source and part of a project called common infrastructure. It is also called common logging. It works with MS Enterprise, log4net and others. It works well.

    0 讨论(0)
  • 2020-12-13 06:52

    Take a look at Castle Windsor Logging Facility.

    Base code is here. Log4net adapter here. NLog adapter here.

    Added adapter for Serilog.

    Without the adapters there is suppor for ConsoleLogger, DiagnosticsLogger, StreamLogger and NullLogger.

    It's pretty easy to write adapters to any other logging framework.

    0 讨论(0)
提交回复
热议问题