Diagnostics logging is a powerful capability in Azure that developers can leverage to track events in their services and troubleshoot them when any issue arises. It is applicable in different Azure services such as Azure App Service, Azure Functions, Logic Apps, Event Hubs, etc. This post will focus on how to enable diagnostics logging in AZ-204 Developing Solutions for Microsoft Azure exam context.
Azure Diagnostics Logging
Azure offers built-in diagnostics to assist with debugging an Azure web app. In the context of the AZ-204 exam, understanding how to enable diagnostics logging in Azure is key. The logs help in auditing, researching, analyzing and troubleshooting the performance of web apps.
Diagnostics logs in Azure can be enabled by following the below steps:
- In the Azure portal, choose your web app.
- On the left menu, scroll down to the `Monitoring` section. Click on `App Service logs`.
- There, you can enable `Application Logging`, `Web Server Logging`, `Detailed error messages`, or `Failed request tracking` as per your requirements.
- Once you have enabled what you need, don’t forget to save.
Moreover, Azure allows developers to enable diagnostics logs programmatically. The code snippet below demonstrates how to enable application logs and web server logs in C# using Azure Management Libraries.
var credentials = SdkContext.AzureCredentialsFactory.FromFile(Environment.GetEnvironmentVariable(“AZURE_AUTH_LOCATION”));
var webApp = Azure.Configure()
.WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
.Authenticate(credentials)
.WithDefaultSubscription()
.WebApps
.GetByResourceGroup(“myResourceGroup”, “myWebApp”);
webApp
.Update()
.WithNewAppServicePlan(PricingTier.StandardS1)
.WithRemoteDebuggingEnabled(RemoteVisualStudioVersion.VS2015)
.WithWebAppAlwaysOn(true)
.DefineDiagnosticLogsConfiguration()
.WithApplicationLoggingStorageBlob()
.WithLogLevel(LogLevel.Information)
.WithStorageAccount(“storageacname”, “/LogFiles”)
.Attach()
.Apply();
Azure Monitoring and Log Analytics
Besides, Microsoft Azure Monitoring provides base-level infrastructure metrics and logs for most services in Microsoft Azure. You can monitor resources with Azure Monitor, visualize them with Azure dashboards and analyze collected data with Azure Log Analytics.
Azure Log Analytics can collect data from various sources like Azure resources, on-premises systems, and other cloud services. This collected data is used mainly for performing advanced log queries to look after the performance and availability of applications and to ensure other resources run smoothly.
Let’s see an example from the Azure portal on how to enable Log Analytics:
- Go to your Log Analytics workspace in the Azure portal.
- Under `General`, select `Data sources` and then `+Add`.
- Under the `Resource Types` dropdown, select the resource for which you want to collect logs.
- Now configure the logs you want to collect and click `Apply`.
Wrap Up
With Azure diagnostics logging, developers are better equipped in ensuring the service’s robustness by identifying and fixing issues efficiently. Whether it’s through Azure portal or programmatically, enabling and configuring diagnostics logging is a crucial skill for the AZ-204 Developing Solutions for Microsoft Azure exam takers.
So, to score high in the AZ-204 exam, understand the different types of logs, how to enable them, and how to use them effectively for troubleshooting and monitoring your Azure resources.
Practice Test
True or False: Diagnostics logging in Azure allows you to log both application and system logs.
- True
- False
Answer: True
Explanation: Azure diagnostic logs give information about the operation of a resource and its features, allowing logging from both application and system.
Which of the following items can be logged in Azure diagnostics logging? (Select all that apply)
- A. System logs
- B. Applications logs
- C. Database logs
- D. Audit logs
Answer: A, B, D
Explanation: Azure diagnostics can log system logs, applications logs and audit logs. It does not directly log database logs.
True or False: An event hub can be used to publish Azure Diagnostic logs directly.
- True
- False
Answer: True
Explanation: Diagnostic logs can be streamed to an event hub for telemetry and analytics.
What type of storage does Azure Diagnostics logging use primarily?
- A. Blob Storage
- B. Table Storage
- C. Queue Storage
- D. Disk Storage
Answer: A. Blob Storage
Explanation: Azure Diagnostic Logs are stored in Azure Storage Blobs.
Multiple select: Which of these services support Diagnostic logging in Azure?
- A. Event Hubs
- B. Application Insights
- C. Logic apps
- D. Azure Traffic Manager
Answer: A, B, C
Explanation: Event Hubs, Application Insights, and Logic Apps all support Diagnostic logging in Azure. Azure Traffic Manager does not support Diagnostic logs.
True or False: Azure Diagnostics Logs are enabled by default.
- True
- False
Answer: False
Explanation: Azure Diagnostic Logs are not enabled by default. They have to be manually enabled per resource.
Single select: Which of the following is NOT a category of Azure Diagnostic Logs?
- A. Administrative
- B. Security
- C. Service Health
- D. Operational
Answer: C. Service Health
Explanation: Azure Diagnostic Logs are categorized into Administrative, Security, and Operational categories. Service Health is not a category in Azure Diagnostic Logs.
True or False: Diagnostic logs can be retained forever without additional costs.
- True
- False
Answer: False
Explanation: Storing diagnostic logs requires storage space, hence will incur additional costs past the initial 90 days.
Single select: Which of the following services can be used for log analysis and visualization in Azure?
- A. Azure Monitor
- B. Azure Logic Apps
- C. Azure Service Bus
- D. Azure Functions
Answer: A. Azure Monitor
Explanation: Azure Monitor is a full stack monitoring service that can be used for log analysis and visualization.
True or False: With Azure Diagnostics, you can export logs to third-party SIEM tools like Splunk.
- True
- False
Answer: True
Explanation: Azure Diagnostic Logs can be integrated with third-party Security Information and Event Management (SIEM) tools like Splunk or Arcsight.
Single select: Which of the following services helps in creating alerts based on the diagnostic logs?
- A. Azure Storage
- B. Azure Monitor
- C. Azure Functions
- D. Azure Logic Apps
Answer: B. Azure Monitor
Explanation: Azure Monitor allows you to create alert rules based on metrics or the analytics query language.
Multiple select: To which targets can Azure Diagnostic logs be streamed?
- A. An event hub
- B. Azure storage account
- C. Logic Apps
- D. Azure Monitor logs
Answer: A, B, D
Explanation: Azure Diagnostic logs can be streamed to an event hub, Azure storage account, and Azure Monitor logs. Though Logic Apps can process diagnostic logs, they are not a streaming target.
True or False: Azure Diagnostics Logs can be analyzed in real-time.
- True
- False
Answer: True
Explanation: Azure Diagnostics Logs can stream data to Azure Monitor logs for real-time analysis.
In Azure Diagnostics Logging, what is the maximum data-retention period in ‘Azure Monitor Logs’?
- A. 30 days
- B. 90 days
- C. 180 days
- D. 360 days
Answer: B. 90 days
Explanation: The data retention period in Azure Monitor Logs Depends on the selected tier, the maximum retention is 90 days with the premium tier.
True or False: Azure Diagnostic Logs only support text format.
- True
- False
Answer: False
Explanation: Azure Diagnostic Logs support both text and JSON formats.
Interview Questions
What is the primary purpose of enabling diagnostics logging in Azure?
The main purpose is to facilitate storing, viewing, and analysing the operation logs and metrics from your Azure resources. It helps in detecting, troubleshooting and resolving issues within Azure applications.
Can Diagnostics logs provide data for an application running in Azure?
Yes, Azure diagnostics logs can provide detailed logs including event logs, performance counters, and crash dumps from the Azure resources that the application interacts with.
What data is captured by the Azure Diagnostic Logs?
Azure Diagnostic Logs capture all events related to activity in Azure. This can include metrics data, logs from the event log, application log data, and crash dumps.
How can you view Diagnostic Logs in Azure?
You can view Diagnostic Logs in Azure Monitor, Azure Log Analytics and Azure Event Hubs, or download them from Azure Storage.
How long does Azure retain diagnostic logs?
Azure retains diagnostic logs for a period of 90 days.
Which Azure services support diagnostic logging?
Most Azure services like App Services, Storage Accounts, Azure SQL Database, Azure Event Hubs, Azure Data Lake Store, Azure Cosmos DB, Azure Search and Azure Redis Cache support diagnostic logging.
Can you export Azure Diagnostic Logs?
Yes, you can archive Diagnostic Logs to a storage account for auditing or manual inspection, stream them to Azure Monitor Logs for detailed analysis and correlation, or send them to Azure Event Hubs for telemetry.
In Azure, apart from Diagnostic Logs, what other types of logs are available?
Apart from Diagnostic Logs, Azure also provides Activity logs, and metrics logs.
What are Activity Logs in Azure?
Activity logs provide insight into operations performed on resources in your subscription. Activity logs can help you understand the operational activities in your subscription, and serve as an audit.
Can you create alerts based on the data from application logs in Azure?
Yes, Azure allows you to create alert rules based on the metrics or the logs data for timely alerts and effective troubleshooting.
What makes up Azure’s unified logging solution?
Azure’s unified logging solution includes activity logs, diagnostic logs and Azure Monitor logs.
What are the different levels of logs granularity provided by Diagnostic logging in Azure?
Diagnostic logging offers four levels of granularity in Azure: Verbose, Information, Warning, and Error.
Is it possible to send diagnostic logs data directly to a third-party SIEM tool?
Yes, by routing the logs to Azure Event Hubs, it is possible to send diagnostic logs data to a third-party SIEM tool.
Do Azure Diagnostics Logs impact the performance of the service?
The diagnostic settings do generate additional storage or data costs, but they generally do not impact the performance of the Azure service.
Can diagnostic logs be turned on for all Azure services at once?
No, logs need to be enabled on a per-resource basis. There is no mechanism to enable diagnostic logs for all resources in a subscription at the same time.