Suppose you’ve gotten applied an software based mostly on a microservices structure. In a microservices-based software, you’ll sometimes have a conglomeration of a number of providers. One of the numerous advantages of microservices structure is that every service is constructed, deployed, and maintained independently, selling excessive scalability.
But let’s say one thing goes fallacious. How would you determine, by wanting on the logs, the place the request failed? Your log recordsdata may embody tons of of hundreds or maybe hundreds of thousands of log messages. Hence looking out via the log entries could be a frightening activity. This is the place correlation IDs come to the rescue.
In a earlier article right here, I talked in regards to the fundamentals of correlation IDs and how one can work with them in ASP.NET Web API. In this text we’ll study how we are able to work with correlation IDs in ASP.NET Core.
To work with the code examples offered on this article, it’s best to have Visual Studio 2019 put in in your system. If you don’t have already got a duplicate, you possibly can obtain Visual Studio 2019 right here.
Create an ASP.NET Core MVC undertaking in Visual Studio 2019
First off, let’s create an ASP.NET Core undertaking in Visual Studio 2019. Following these steps will create a brand new ASP.NET Core MVC 5 undertaking in Visual Studio 2019.
- Launch the Visual Studio IDE.
- Click on “Create new project.”
- In the “Create new project” window, choose “ASP.NET Core Web App (Model-View-Controller)” from the checklist of templates displayed.
- Click Next.
- In the “Configure your new project” window, specify the identify and site for the brand new undertaking.
- Optionally test the “Place solution and project in the same directory” test field, relying in your preferences.
- Click Next.
- In the “Additional Information” window proven subsequent, choose .NET 5.zero because the goal framework from the drop-down checklist on the prime. Leave the “Authentication Type” as “None” (default).
- Ensure that the test containers “Enable Docker,” “Configure for HTTPS,” and “Enable Razor runtime compilation” are unchecked as we received’t be utilizing any of these options right here.
- Click Create.
Next create a brand new controller on this undertaking — let or not it’s named ValuesController (that’s the default identify). We’ll use this ASP.NET Core MVC undertaking and controller to work with correlation IDs within the subsequent sections of this text.
What are correlation IDs? Why are they helpful?
Correlation IDs are distinctive identifiers that allow you to correlate…