AZ-204 Developing Solutions for Microsoft Azure Exam

You can develop, but can you develop for the cloud? Harness your development skills and learn how to create robust solutions for Microsoft Azure, aiming for your Microsoft Certified: Azure Developer Associate certification!

Practice Test

Exam

Configure and implement diagnostics and logging

Set Up Application Insights for Web Apps

Application Insights is an Azure Monitor feature that helps you collect telemetry data and gain visibility into Web Apps running on Azure App Service. By sending real-time diagnostic data to an Application Insights resource, you can quickly detect performance issues, errors, and user behavior patterns. This setup works without changing your production environment, making it safe and reliable. Application Insights supports both ASP.NET and ASP.NET Core apps on any hosting OS.

Application Insights collects various telemetry types to help you understand app behavior:

  • Requests: Tracks incoming HTTP calls and response times.
  • Dependencies: Monitors calls to databases, external services, and storage.
  • Exceptions: Captures unhandled errors and stack traces.
  • Performance counters: Reports CPU, memory, and other system metrics.
  • Traces (Logs): Records custom log messages from your code.
    Custom events & metrics and availability tests require additional setup for advanced scenarios.

To enable Application Insights, you need an Azure subscription and an Application Insights resource. You also need a functioning ASP.NET or ASP.NET Core app and Visual Studio with the Azure development tools. You can add the SDK automatically by right-clicking your project in Visual Studio, selecting Add Application Insights, and providing your resource details. The SDK then injects the necessary configuration, such as a connection string or instrumentation key, so telemetry begins at runtime.

Integrating Application Insights with your logging framework (like ILogger, log4net, or NLog) helps you collect detailed logs for deeper diagnostics. Use TelemetryClient.TrackTrace to send custom messages and include operation IDs or correlation IDs to link logs with specific requests. Avoid overly verbose logging and do not log sensitive user data to maintain security. Finally, you can create availability tests and custom dashboards in the portal to monitor uptime, set alerts, and share insights with your team in real time.

Conclusion

Monitoring and logging are vital for maintaining healthy Web Apps in Azure. Using Application Insights gives you real-time telemetry and centralized diagnostics so you can find and fix issues quickly. With built-in support for different frameworks, you can add this feature without changing your production code.

Collecting key telemetry types—including requests, dependencies, exceptions, performance counters, and traces—helps you understand how your app behaves under load. Integrating with a logging framework and using correlation IDs makes it easier to trace problems across components. Always balance detail with security by avoiding excessive logs and never storing sensitive data in your telemetry.

Finally, creating availability tests and custom dashboards lets you set up alerts and share insights with your team. This proactive approach ensures you detect downtime and performance issues before your users do. By following these best practices, you can keep your Azure Web Apps reliable and performant.