Set Up Application Insights for Web Apps
Telemetry Collection and Types
Application Insights is an Azure Monitor feature designed to collect telemetry and monitor the health of web apps running on Azure App Service. When you integrate this service, real-time diagnostic data flows from your application to an Application Insights resource. This setup allows you to identify performance bottlenecks, errors, and user trends without disrupting your live environment. The service automatically tracks several telemetry types, including incoming HTTP requests, dependency calls to databases, and unhandled exceptions. You can also monitor performance counters and record custom traces using your existing logging framework.
Enabling Application Insights
To set up this monitoring capability, you need an active Azure subscription and an Application Insights workspace resource. If you use Visual Studio, you can add Application Insights to your ASP.NET or ASP.NET Core project automatically through the solution explorer interface. The development environment then injects the required connection string or instrumentation key directly into your application configuration. For cross-platform or newer systems, developers can implement the Azure Monitor OpenTelemetry Distro to achieve the same standard telemetry tracking.
Log Integration and Dashboards
Developers can enrich their telemetry by routing custom code logs to Application Insights using platforms like ILogger or by calling TelemetryClient directly. To ensure these logs are useful, configure your framework to capture at least Information level events and include correlation IDs to link log entries with specific HTTP requests. You can also set up availability tests, such as standard URL ping tests, to periodically check if your application is active. To visualize this data, developers configure custom dashboards in the Azure portal, pinning critical metric charts to track live application health.
Logging Types in Azure App Service
Application logging and web server logging are key diagnostics that capture both developer-defined messages and raw server transactions inside Azure App Service. Application logs represent code-level events classified by severity states like Critical, Error, Warning, Info, Debug, or Trace. Web server logs record raw HTTP traffic in the standard W3C extended log file format, which includes client IP addresses and status codes. For deep troubleshooting, you can also enable detailed error logging to save copies of failed web pages and failed request tracing to track internal web server components.
Storage Choices and Configuration
You can configure these logging tools using the Azure portal or the Azure CLI. When running Windows apps, you must decide where to save your logs based on your storage needs. Choose the local file system for short-term debugging, or choose Azure Blob Storage for long-term retention and larger log volumes. Keep in mind that Linux and container apps are restricted to local file system storage, which requires you to define strict disk quotas and retention periods. If you regenerate the access keys for your Azure storage account, you must update your logging configuration to prevent connection failures.
Accessing and Managing Logs
Once logs are enabled, you can download them using FTP or access them through the Kudu console browser interface. For immediate debugging, developers can stream live logs directly to the Azure portal, Azure Cloud Shell, or a local terminal. Effective log management depends on selecting the right log levels, such as using Verbose during active development and switching to Error in production. This practice helps control storage costs and prevents system noise. Additionally, you should implement log rotation policies and restrict access to secure sensitive information in your logs.
Implement Diagnostic Settings and Log Streaming
Diagnostic Settings and Routing Targets
To manage the diverse logs generated by your web apps, you must configure diagnostic settings to route telemetry to specific endpoints. You can choose different targets depending on your long-term goals for the data. Sending logs to Azure Storage provides cheap, long-term archival. If you need to send telemetry to third-party tools or external security systems, choose Azure Event Hubs to stream the data in real time. For deep query capabilities and advanced analysis, the best choice is routing logs to a Log Analytics workspace.
Real-Time Streaming and Kudu Forensic Access
When you need to diagnose live issues immediately, log streaming displays console outputs and file updates as they happen. You can start a live stream using the Azure portal or run the az webapp log tail command in the Azure CLI. This bypasses the typical ingestion delay required for log database processing. If automated diagnostic pipelines fail, developers can log into the SCM site of the Kudu engine to extract a diagnostic dump. This provides direct access to the raw directory structure and log files on the underlying file system.
Telemetry Analysis with Kusto Query Language
Once telemetry reaches a Log Analytics workspace, you can perform complex queries using the Kusto Query Language (KQL). KQL allows you to search, filter, and structure raw table data to find systemic issues or traffic anomalies. For example, you can query specific tables like AppServiceHTTPLogs to filter for HTTP 500 errors and correlate them with application exceptions. Mastering KQL allows developers to quickly build dashboards, set up alerts, and maintain visibility over complex cloud architectures.