Q:

Serilog integration in .Net core 2.0 Class Library Project

I would like to use Serilog for logging in .Net core 2.0 class library project. I have searched many places and did not find any example for integrating the Serilog in class library project. Can anybody refer a sample?  
Thanks.

A:

You should not set up Serilog logging inside of a class library. A class library is for consumption by other applications, for example an ASP.NET Core web application, or a console application or whatever. The class library is not the entry point of the application, so it should not be responsible for setting up application wide things like logging. It would also be very difficult to do so because a class library does not have a central entry point (by design), so where exactly would you expect to set logging up?
Instead, your library should simply rely on logging to be there and have a way to receive loggers when it needs them. If your application is built with dependency injection in mind, you can just inject your loggers where you need them.
It’s then the responsibility of the application entry point to set up logging and to provide your library with the logging infrastructure.
So if you are using this in an ASP.NET Core context, just follow the guidelines on how to set up Serilog with ASP.NET Core.

