How to send Azure activity logs to a Log Analytics workspace
This guide sets up a subscription-level diagnostic setting so your Azure activity log is kept in a Log Analytics workspace instead of disappearing after 90 days. It is for Azure admins and security owners who need to answer who changed what, and when, after the default window has closed.
Before you start
Before you start
The activity log records management (control plane) operations such as creating a virtual machine or changing a key vault access policy. Azure collects it by default and keeps it for 90 days; a diagnostic setting is how you keep it longer and query it.
- Permissions: Azure RBAC access that lets you create diagnostic settings on the subscription and write to the destination workspace. If the workspace is in another subscription, you need access to both.
- A Log Analytics workspace that already exists. The destination must exist before you create the setting.
- Tools: the Azure portal, or Azure CLI signed in with
az login. - Scope: one setting per subscription you want to cover. Repeat the steps for each subscription.
Step by step
Step by step
- Pick or create the destination workspace. Decide who may read it, because it will hold a record of every management change in the subscription.
- In the Azure portal open Monitor > Activity log and select Export Activity Logs.
- Select the subscription, then Add diagnostic setting.
- Give the setting a descriptive name, for example
activity-log-to-workspace. - Under Logs, tick every activity log category. Microsoft lists these categories: Administrative, Security, ServiceHealth, Alert, Recommendation, Policy, Autoscale and ResourceHealth.
- Under Destination details, tick Send to Log Analytics workspace and choose the subscription and workspace.
- Select Save. Data should start to arrive within 90 minutes; the AzureActivity table is created when the first record lands.
- Decide how long the workspace should keep the data. Microsoft documents that retention can be raised to up to 12 years for the activity log table; the default activity log retention outside a workspace is 90 days.
- If you earlier exported the activity log with a legacy log profile, turn that off so you do not collect the same events twice.
The CLI equivalent of steps 3 to 7 is shown in the next section, after the read-only check, because it changes the subscription.
Check it worked
Check it worked
These commands only read. List the diagnostic settings on the current subscription and confirm one of them has your workspace and all categories enabled:
az monitor diagnostic-settings subscription list
After the first events have arrived, run this query in the workspace under Logs. It should return one row per category that has produced events:
AzureActivity
| summarize count() by CategoryValue
Change: CLI alternative to the portal steps
This changes your subscription. It creates a diagnostic setting. Replace the placeholders and run it only against the subscription you intend to change.
az monitor diagnostic-settings subscription create \
--name activity-log-to-workspace \
--location <region> \
--workspace /subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.OperationalInsights/workspaces/<workspace-name> \
--logs "[{category:Administrative,enabled:true},{category:Security,enabled:true},{category:ServiceHealth,enabled:true},{category:Alert,enabled:true},{category:Recommendation,enabled:true},{category:Policy,enabled:true},{category:Autoscale,enabled:true},{category:ResourceHealth,enabled:true}]"Common mistakes
Common mistakes
- Only the default 90 days. Without a diagnostic setting, older events, including who created a resource, are gone.
- One subscription only. The setting is per subscription. A management group setting does not capture every subscription-level event, so keep a subscription-level setting for each subscription you care about.
- Picking a few categories. If you need the full picture, select all of them; you can reduce later.
- Duplicate events. A legacy log profile, or a management group setting plus a subscription setting sending to the same place, produces duplicates.
- Expecting failed sign-ins. The activity log is not an authentication audit log. Requests rejected before an operation starts do not appear.
- Wide workspace access. Anyone who can read the workspace can read your change history.
How ConfigCobra helps
How ConfigCobra helps
ConfigCobra is read-only and never changes your Azure environment. Its Azure scan covers the four CIS Microsoft Azure benchmarks (339 controls, with Foundations v6.0.0 at 127), using Reader access on the subscriptions you choose. Two of those Foundations checks relate to this guide: a diagnostic setting exists for subscription activity logs (6.1.1.1) and that setting captures appropriate categories (6.1.1.2).
- Findings point at the exact Azure resource.
- Remediation impact analysis shows the affected resources and identities before you apply a fix.
- Scheduled scans (daily, weekly or monthly) and drift detection alert you by email if a control regresses.
Go further
- All guidesAdmin how-tos for Microsoft 365, Azure, Google Cloud and AWS
- Check libraryEvery CIS check, explained
- RemediationSee what a fix changes in your tenant before you apply it, then use the generated script
- Inventory & InsightsEvery user, app, device and resource in one inventory, with built-in risk views
See where your Microsoft Azure stands
A read-only assessment against the CIS benchmarks, prioritised so you know what to fix first.