Logging all requests with Serilog and Seq
There are many community projects for logging ASP.NET Core Web APIs. We are going to focus on Serilog for one simple reason. Serilog specializes in working with structured objects and not just text. This is called structured logging.
It is typically a bad idea to save logs in your main database. Logging generates a vast amount of information, which can place a significant strain on your main database. Furthermore, your database is optimized to query and return application data, not for the high-volume, write-heavy nature of logging. We will instead use Seq as our log sink. Seq is free for local use. In this recipe, we will set up Seq in a Docker container and use the Serilog middleware to log every request.
Getting ready
The starter project for this recipe can be found here: https://github.com/PacktPublishing/ASP.NET-9-Web-API-Cookbook/tree/main/start/chapter05/SeqWithSerilog.
How to do it…
- Confirm that Docker is...