How to use Serilog in multiple API/Web projects?

I have a solution containing multiple .NET Core API and a .NET Core Web application. How can I integrate Serilog in such a way that I will not be required to make changes at 10 different places for adding a column or changing some property.

Also, I want to use LoggingLevelSwitch to change the Logging Level at runtime, so on every request that will be read from appsettings.json using IOptionsSnapshot. LogLevel and the connection string are the two properties I would like to keep in my API/.Net Core Web Project.

Is it possible to do all other instantiation in a Class Library project with Serilog.AspNetCore and Serilog.Sinks.MsSqlServer as dependencies?

Currently, I am creating the Configuration object in Program.cs and retrieving connectionString from appsettings.json and passing it to an extension method that i created in a class library project.

Here is the link of the Pastebin for the extension method: https://pastebin.com/FSMXmH8L I am not too sure if this is even the right direction, kindly help.

TIA

submitted by /u/wannabeIndLeader
[link] [comments]

Leave a Reply