Core 2.0: Logging
Introduction
Logging framework is important in the architecture of any project, it’s integrated usually in the Cross-Cutting Layer because it a common operation that will be used in all layers.
And to ensure that, I will explain in this article the log integration.
Some tools and frameworks can be used to log, we illustrate as a sample: Log4net (we will use it in this blog), ELMAH, NLog, Microsoft Enterprise Library, NSpring , ObjectGuy Framework, Serilog, JSNLog and others are used but they are paid like SmartInspect and Loggr.
And we have more framework added on nuget.
The logger most used in .NET is Apache log4net, it’s similar to log4j in Java.
We create a new class library solution.
After, we will create the class library project
Add log4net Package
We install the package by searching into Visual Studio or we run the command below in the Package Manager Console.
PM> Install-Package log4net -Version 2.0.8
If we want to use an XML file, we can add a new config file named: App.config
https://github.com/didourebai/CrossLayer/edit/master/CrossLayer.Logger/App.Config
Add a new Logger Manager
We create a new folder called Logging that includes an interface: ILogger and a class: Logger that inherit from it.
The Logger Class manage all operation used when we log.
https://github.com/didourebai/CrossLayer/blob/master/CrossLayer.Logger/Logging/Logger.cs