A single file for you to either copy/paste or install via nuget, into your library/framework/application to enable dependency free logging. It contains transparent built-in support for NLog, Log4Net, EntLib Logging, Serilog and Loupe or allows the user to define a custom provider.
When the DLL is added, It Just Works. i.e., all that's needed is to reference NLog / Log4Net in your app root so it ends up in the output directory and your component will automatically log without the user having to do any wireup or configuration. Loggers are either invoked dynamically (which is optimized) or via compiled expressions (also optimized).
The ILog interface consists of just 2 methods, which contrasts with the large interface (~65 members) in Log4Net and Common.Logging.
A logging implementation is an application level concern. Your library / framework should not have any dependencies on any specific logging library, but may still need to support logging.
What about a shared Common.Logging you ask? No, you're still introducing a dependency that has the usual versioning concerns and adds yet another item to the consumers projects' references as well as a package reference.
The file provides:
- an
ILoginterface in your library that your code consumes. - An
ILogProvideryour framework / library / application uses to get a logger. - A static location where the application developer can set the
ILogProviderand where you can retrieve it.
The included providers, NLogProvider, Log4NetProvider, SerilogProvider, EntLibLogProvider, LoupeLogProvider serve as templates for an application developer can follow to define their own custom provider.
- Copy LibLog.cs into your library and manually change the namespace OR install the nuget package which contains the source and which will automatically set the namespace to your project's root namespace.
- To get a current class logger:
public class MyClass
{
private static readonly ILog Logger = LogProvider.For<MyClass>();
public MyClass()
{
Logger.Info(....);
}
}Consumers can define their own provider in their application code to support custom loggers, decorate, etc:
YourComponent.Logging.LogProvider.SetCurrentLogProvider(new CustomLogProvider())LibLog is licensed under MIT Licence.
Feedback, compliments or criticism: @randompunter


