Events
Mar 17, 9 PM - Mar 21, 10 AM
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
To understand how your Azure service is performing, you need to understand which logging, metrics, and alerts are available and how to use them.
Use the following table to understand what information you can learn about your Azure resources and why you should use logging, metrics, and alerts.
Type
Example questions
Azure hosting
Hosting services such as Azure App Service and Azure Functions provide several forms of feedback to answer questions such as:
Azure service
Azure offers metrics for services, so you can get answers to questions such as:
Azure SDK
The Azure SDKs provide access to Azure from many programming languages. The SDKs provide logging so that you can ask questions such as:
Your code or container
To understand how your own code or container is working, integrate Application Insights from Azure Monitor. You can use Application Insights to capture logs across services for a single application to ask questions such as:
Type | Availability | Description |
---|---|---|
Metrics | Provided without configuration | Start with metrics because every Azure service has some metrics to help you evaluate how it's performing. |
Alerts | Configurable | Configure alerts to be notified when negative or quota-expiring behaviors happen. |
Logging | Configurable | Some services, such as hosting services, have logging to help you understand how your code or container is behaving. You might need to configure logging before you can open log files. |
Custom logging | Configurable via code | From your own code, you can log to Azure Monitor by using the Application Insights SDK for server and client applications. The code doesn't have to be hosted on Azure to log to Azure Monitor. |
To view metrics for your resource on a scheduled basis, open the Azure portal and go to Monitoring > Metrics.
Set alerts for your resources in the Azure portal. Alerts can include specific metrics, communication streams (such as email), and frequency. Common alerts to set are total:
You can configure hosted applications and containers to log information about:
Turn on these logs to understand how your hosted application behaves. These logs are probably the first place where you'll learn that your deployment failed or that your startup configuration is incorrectly configured or missing dependencies.
Azure web apps and Azure functions automatically provide custom logging to stdout
and stderr
, if you use the correct logging functions:
console.log('your message here')
.context.log('your message here')
.You can add richer custom logging by using Application Insights in Azure Monitor. Application Insights offers server (Node.js) and client (browser) scenarios:
enableAutoCollectConsole: true
in order to collect custom console logs.For application logging, Application Insights can provide:
To turn on application host logging in the Azure portal:
When you turn on application logs, the logs are stored in the Logs folder of your web app host. View the logs from either the Azure portal or the Visual Studio Code extension for App Service.
Name formats for log files include:
{DATE-TIME}_{RANDOM-CHARS}_{docker}.log
{DATE-TIME}_{RANDOM-CHARS}_default_docker.log
For App Service, use the following table to learn more about how to stream logs.
Method | Description |
---|---|
Azure CLI | Run az webapp log tail. |
App Service extension in Visual Studio Code | Right-click the resource, and then select Start streaming logs. |
See the earlier steps to turn on host logging for App Service.
With a consumption-based function app, if you use the logging that the context object in your source code provides, those logs appear under each function's Monitor section. The Azure portal also gives you the option to stream the logs as requests come in to the function.
When you use context.log
in a function app or console.log
in a web app, and you have Application Insights turned on, those custom logs are added to your Application Insights resource in the Trace table. If you prefix your custom log with a specific string, such as JavaScript
, you can use Kusto Query Language to search the Trace table for any messages that contain that prefix when you want to reduce your log to just those custom entries.
traces
| where message contains "JavaScript"
If you're trying out Application Insights by running code locally, and that code uses one of the Application Insights npm packages, be sure to call the flush()
method so the logging is sent to Application Insights immediately. When you view the logs, remember that it can still take a couple of minutes before your custom logs are available in Application Insights.
To view failures for resources that you monitor in Application Insights, use the Failures pane.
Events
Mar 17, 9 PM - Mar 21, 10 AM
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowTraining
Module
Capture Web Application Logs with App Service Diagnostics Logging - Training
Learn about how to capture trace output from your Azure web apps. View a live log stream and download logs files for offline analysis.
Certification
Microsoft Certified: Azure Administrator Associate - Certifications
Demonstrate key skills to configure, manage, secure, and administer key professional functions in Microsoft Azure.