Create a common Serilog library to centralize the logging configuration throughout microservices
Still making use of appsettings but simpler
"MySerilogLibrary": {
"ApplicationName": "my-serilog-library-api",
"Environment": "Development",
"MinimumLevel": "Information",
"LokiUrl": "http://localhost:3100",
"SeqUrl": "http://localhost:5341"
}
Also, on IHostBuilder (Program.cs), the UseSerilog is needed:
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseSerilog()// wire serilog to aspnet core
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
Final note, add this line to log all requests made to API on Configure method at Startup.cs
app.UseSerilogRequestLogging();
Is based on Project Tye. Getting Started here.
On Solution Folder, on your shell of your choice type
tye run
- .NET 5.0
- ASP.NET Core 5.0
- Swagger
- Serilog
- Project Tye
This project is licensed with the MIT license.