Introduction
In this article, we learn about how to use application insights in local environments for ASP Core applications, configuration, and setup from end to end.
Prerequisites
- MVC Core
- Web API Core
- Console Application
Follow the below steps.
Step 1
- Open Visual Studio 2019 -> Goto File --> Project ,
- Search 'Blank Solution' in the search bar to further filter the templates,
- Select 'Blank Solution' and Click on the 'Next' option, as shown below.
Step 2
Provide a valid solution name your blank solution, choose a disk location for the solution code path, and click on the 'Create' button.
Step 3
Now an Empty Solution was created. Next, create a new MVC core web application by right-clicking on the solution, which is shown below.
Step 4
As shown in the below image, we have the option to create a new project. So, name your project and click on the 'Create' button.
If you want to add an additional project to a solution, right-click the solution node in Solution Explorer and choose Add > New Project .
Step 5
Select .NET Core and ASP.NET Core 3.1 as shown in below filters and Select MVC Web application and click on the 'Create' button as shown in the below screengrab.
Step 6
If you want to add an additional project to a solution, right-click the solution node in Solution Explorer and choose Add > New Project .
Now we are required to have one more application for API. Select valid filters and Web API project template, then click on the 'Create' button.
Step 7
Now go to your VS 2019, right-click on my solution and select ‘Add Solution To Source Control’ for a solution path to push my code in GITHUB.
Step 8
Go to Team explorer -- > connect symbol --> select valid email id's to create a new repository and click on publish.
Step 9
Now we successfully pushed code to the GITHUB repository,
Note: If you've any issues with code pushing, the error will be logged in the output panel in Visual Studio 2019
Step 10
Add a model class in the Model folder in Web API project for Department entities.
Step 11
Add a model class in the Model folder in Web API project for Employee entities.
Step 12
Add Repository Folder for DBContext class, Add Employees and Departments references as shown in the below screenshot.
Note: Use migration commands by configuring valid DB connection string. I'm using free SQL server services from
here.
Step 13
Add API Controller for Employee and Department using EF, as shown in the below screenshots.
- Right-Click on your Controllers Folder in the project node. Click on Add New Item, and select the API controller with actions using the entity framework. Then click on 'Add' button
Department Controller
Select the Department Model and Data context class i.e., 'DBContext'. The controller name is Departments Controller.
Department Controller
- Use CRUD operations which are created by Department Controller Creation Process.
Step 14 - Employee Controller
- Follow Step 13 process for the Employee Controller creation process.
Step 15
Now install application insights references through the NuGet package manager, as shown in the below screenshot.
Step 16
Click ‘OK’ to confirm dependencies for AI. ASP.NET Core dependencies is prompted, as shown below.
Step 17
Click on the ‘I Accept’ button for license acceptance.
Step 18
Now configure the application instrumentation key in your appsettings.json file. (If you’re using .net framework, you need to configure in web.config file under the app settings section).
Step 19
Add application insights telemetry in Startup.cs, as shown in the below screenshot.
Now the Local Environment setup has been completed for Application Insights learning. In the next article, we'll look into more about how Application Insights performance and help the developer fix bugs by using Visual Studio 2019.