Is there a logging facade for the .NET world?

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 logging implementations as needed just makes sense. Furthermore, the wrapper APIs available in slf4j have saved me many times when I needed to use a third-party library that was coded against a single logging framework that I wasn't using.

Is there a project out there that acts as a facade between loggers like log4net, nLog and Enterprise Library? Are there wrappers that allow me to shortcut calls to those libraries and direct them to another library? Should I start out an open source project to do this myself? Is this question a duplicate because I don't know the right way to ask? Conversely, is the common way to do this using aspect orient programming?


Solution 1:

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.

Solution 2:

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.

Solution 3:

I'm incorporating Simple Logging Facade because it appears to support The Object Guy's Logging Framework for .Net out of the box.

Solution 4:

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

Solution 5:

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'