Azure Insights: .NET Core API
Monitor your ASP .NET Web API with Azure Application Insights
Create your .NET Core Web API
Include Application insights in the .NET Core API.
Deploy the code to Azure API service
View Insights and metrics on Azure dashboard
For our article purposes I am using my personal API with the following route’s and methods, we will be able to see these routes GET requests on Insights dashboard.
Create new or use existing .NET Core API
Add Application Insights NuGet packages to your project:
Go to Azure portal and use the Application Insights that comes with your API service plan and get the Instrumentation key:
Add the instrumentation key into ApplicationInsights section in appsettings.json
{
"ApplicationInsights": {
"InstrumentationKey": "putinstrumentationkeyhere"
},
"Logging": {
"LogLevel": {
"Default": "Warning"
}
}
}
Add configuring Application insights telemetry in Startup.cs file
public void ConfigureServices(IServiceCollection services)
{
...
services.AddApplicationInsightsTelemetry();
services.AddControllers();
}
Run your application locally and test your API (using Postman or any Rest Client). These queries can be seen on the insights dashboard.
Application Insights are provided along with your App Service plan, even for free tier. Make use of some default log queries provided to filter and also see exceptions and failures. This helps debug your API as well.
In conclusion:
The Application Insights can monitor your applications no matter where or how they run. If your application is running and has network connectivity to Azure, telemetry can be collected. Application Insights monitoring is supported everywhere .NET Core is supported.