I am using Serilog for logging in asp.net core website and there is 'class library' used in the project.
- How can we implement logging in asp.net core class library?
- Is there any way to implement logging independently in 'class library' ?
I am using Serilog for logging in asp.net core website and there is 'class library' used in the project.
Simply, you add the
Microsoft.Extensions.LoggingNuGet package to your class library, and then injectILogger<T>into your classes:ILoggeris a facade, an API for logging that doesn't actually do any logging itself. The actual logging happens via providers that you plug into the facade when you have a real application using it. This is where something like Serilog would come in. In your actual application, you'd configure logging to use Serilog, and then any time anything calls a method onILogger, that gets proxied over to your actual real logging provider (Serilog), and then Serilog does the actual logging.