Adding logging to our API in middleware
In simple words, logging is nothing but the process or act of getting log files in one place to get the events or other actions that occur in APIs during communication. In this section, we will implement logging for our product APIs.
Before we start looking at how to log our APIs' events, let's first take a quick look at our existing product APIs.
Note
Refer to the Request delegates section to refresh your memory as to how you can create a new ASP.NET Core project.
The following screenshot shows the project structure of our product APIs:

Here is our Product
model:
public class Product { public Guid Id { get; set; } public string Name { get; set; } public string Description { get; set; } public string Image { get; set; } public decimal Price { get; set; } public Guid CategoryId { get; set; } public virtual Category Category { get; set; } }
The Product
model is a class that represents a product, containing properties.
Here is our repository interface...