Send logs to a Log Analytics workspace and query them

Azure Portal, Hands On20 minutes, plus waitingFree tierSteps checked 28 October 2026By Cloud Hands On

In this task you'll send logs to a Log Analytics workspace and query them.

A Log Analytics workspace collects logs from your resources in one place, where you can search them with KQL (Kusto Query Language). It's the store behind most of Azure Monitor, Defender and Sentinel.

Resources send logs to a workspace through diagnostic settings. A good first source is the subscription's activity log, because sending it to a workspace costs nothing extra.

Example. Ironbridge Payments sends its key vault's audit logs to a workspace and runs a weekly query listing every secret read outside office hours.

Before you start

You need: Log Analytics Contributor or Contributor. Time: 20 minutes, plus waiting.

Where to look

  1. Home
  2. Log Analytics workspaces
  3. + Create

Steps

  1. Open Log Analytics workspaces, select + Create, choose rg-portal-practice, name it law-practice, pick your region and create it.
  2. Open Monitor, Activity log, and select Export Activity Logs. Choose your subscription and select + Add diagnostic setting.
  3. Name it to-law-practice, tick the Administrative category, choose Send to Log Analytics workspace and pick law-practice. Select Save.From now on, new activity log events also go to the workspace.
  4. Make a change to generate an event, such as adding a tag to a resource group, then wait 15 minutes or more.The first activity log rows can take up to an hour to arrive in a new workspace. If the query comes back empty, try again later.
  5. Open law-practice and select Logs. Close the welcome video and the Queries hub window if they open. If the Agent switch at the top is on, turn it off, then change Simple mode to KQL mode.
  6. Type AzureActivity | where TimeGenerated > ago(1d) | summarize count() by OperationNameValue | order by count_ desc, select Run (or press Shift+Enter) and read the Results tab.Each line is a kind of change and how many times it happened.

Commands

# Create the workspace
az monitor log-analytics workspace create --resource-group rg-portal-practice \
  --workspace-name law-practice

# Send the subscription's administrative activity log to it
az monitor diagnostic-settings subscription create --name to-law-practice --location uksouth \
  --workspace $(az monitor log-analytics workspace show --resource-group rg-portal-practice --workspace-name law-practice --query id --output tsv) \
  --logs '[{"category":"Administrative","enabled":true}]'

# Query it (the workspace ID here is its customer ID, a GUID)
az monitor log-analytics query \
  --workspace $(az monitor log-analytics workspace show --resource-group rg-portal-practice --workspace-name law-practice --query customerId --output tsv) \
  --analytics-query "AzureActivity | take 10" --output table

Watch out for

Cost
Logs are charged per GB that goes in, with a small free allowance each month, and retention beyond 31 days costs extra. Activity log data is free to send; other logs, such as VM or Container Apps logs, are not.
Security
Logs often contain names, IP addresses and other sensitive details. Limit who can read the workspace, and send only the categories you need.
Common mistakes
Turning on every log category for every resource, then getting a surprise bill. Querying straight after setting up and thinking it's broken, when the data just hasn't arrived yet.

Clean up

  1. Monitor
  2. Activity log
  3. Export Activity Logs

Delete the to-law-practice diagnostic setting (it's on the subscription, so deleting the resource group won't remove it). Then delete the resource group to remove the workspace.

Words to know

Workspace
The store where logs are kept and queried.
Diagnostic setting
A rule on a resource that says which logs to send, and where.
KQL
Kusto Query Language: a read-only query language that pipes data from one step to the next with |.
Retention
How long logs are kept. 31 days is included for most data; longer costs more.

Tick off each step and track your progress in the guide.

Open this task in Azure Portal, Hands On

Keep going