Lesson 2 of 5 Monitoring Resources with Azure Monitor

Routing Logs with Diagnostic Settings and Data Collection Rules

This lesson explains the kinds of Azure logs, diagnostic settings, data collection from VMs and Log Analytics workspace settings.

Learning outcomes

After completing this lesson, you will be able to:

  • Distinguish between the activity log, resource logs and guest OS logs.
  • Choose a diagnostic setting destination for a requirement.
  • Describe the Azure Monitor Agent, data collection rules and workspace retention.

Kinds of logs

Azure has three main kinds of platform logs. The activity log records subscription-level control plane events: who created, changed or deleted a resource, service health events, autoscale and policy actions. It is collected automatically and kept for 90 days. Resource logs record operations inside a resource, such as Key Vault secret reads, storage blob requests, NSG rule counters or Azure SQL query statistics; they are not collected until a diagnostic setting routes them. Microsoft Entra logs (sign-ins and audit) are routed from Microsoft Entra ID's own diagnostic settings.

Sort into groups

Which log records it?

Exam skills 5.1.2

Decide which kind of log records each event.

Log in to try this activity Interactive activities are free with an account.

Diagnostic settings

A diagnostic setting on a resource selects log categories (or category groups such as allLogs and audit) and optionally metrics, and sends them to one or more destinations. Each resource can have up to five diagnostic settings, and the activity log has its own diagnostic setting at subscription level.

Log Analytics workspace
PurposeQuery with KQL, alerts, workbooks, Insights
Query in Azure MonitorYes
Choose when Analysis and alerting
Storage account
PurposeLow-cost archive and audit
Query in Azure MonitorNo
Choose when Long-term retention at low cost
Event hub
PurposeStream to SIEM or external tools
Query in Azure MonitorNo
Choose when Third-party tools
Partner solution
PurposeIntegrated partner monitoring
Query in Azure MonitorNo
Choose when Partner platforms

At scale, Azure Policy built-in definitions with DeployIfNotExists create diagnostic settings for every resource of a type, so new resources are covered automatically. Logs sent to a workspace land in tables such as AzureDiagnostics (legacy shared table) or resource-specific tables such as StorageBlobLogs and AzureFirewallNetworkRule, which are preferred.

The following diagram shows a policy, the diagnostic setting it deploys and the two destinations for auditing secret reads across 40 key vaults.

Auditing secret reads across 40 key vaults, including new ones. The built-in DeployIfNotExists policy configures diagnostic settings that send AuditEvent to a Log Analytics workspace with one year of retention for queries and to a storage account for the seven-year archive; a remediation task covers the existing vaults.
Workspace long-term retention is an alternative to the storage archive.
Match the pairs

Choosing a destination

Exam skills 5.1.2

Match each requirement with the diagnostic setting destination that meets it.

Log in to try this activity Interactive activities are free with an account.

Collecting data from VMs

Logs from inside VMs, such as Windows event logs, Linux syslog, performance counters and text logs, are collected by the Azure Monitor Agent (AMA), an extension installed on Windows and Linux VMs, scale sets and Arc-enabled servers. What to collect and where to send it are defined in data collection rules (DCRs), which are associated with machines; one DCR can serve many machines, and a machine can have several DCRs. The legacy Log Analytics agent (MMA/OMS) retired on 31 August 2024 and must not be used.

True or false

Agents and data collection rules

Exam skills 5.1.2

Check how data is collected from inside VMs.

Log in to try this activity Interactive activities are free with an account.

Log Analytics workspaces

A Log Analytics workspace stores log data in tables. Its settings include retention (the Analytics plan includes 31 days, configurable per workspace or table up to two years of interactive retention and up to 12 years in total with long-term retention), table plans (Analytics for full querying and alerts, Basic and Auxiliary for high-volume, lower-cost logs with limited querying), a daily cap to limit ingestion, and the access control mode (workspace or resource-context permissions). Commitment tiers reduce cost for high ingestion volumes.

Scenario questions

Workspace settings

Exam skills 5.1.2

Choose the workspace setting that meets each requirement.

Log in to try this activity Interactive activities are free with an account.
Worked example

Auditing Key Vault access

The security team must be able to query who read secrets from 40 key vaults over the last year and to keep the raw logs for seven years at the lowest cost. New key vaults must be covered automatically. What should you configure?

Assign the built-in DeployIfNotExists policy that configures diagnostic settings for Key Vault, sending the AuditEvent category to a Log Analytics workspace with one year of retention for querying, and to a storage account for the seven-year archive (or use workspace long-term retention). Create a remediation task for the existing vaults. The activity log would show changes to the vaults but not secret reads, which are data plane operations.

Check yourself

Are Key Vault resource logs collected without any configuration?

Show answer

No. Resource logs need a diagnostic setting that routes them to a destination.

Exam Tips

Remember for the exam

  • Resource logs need a diagnostic setting; the activity log is collected automatically for 90 days.
  • Send logs to Log Analytics to query and alert; to storage to archive; to Event Hubs to stream.
  • Collect guest OS logs with the Azure Monitor Agent and data collection rules.
  • Deploy diagnostic settings at scale with DeployIfNotExists policies.