Log Analytics and KQL Fundamentals
Ingest diagnostic logs into a Log Analytics workspace and write Kusto Query Language queries to filter, aggregate, and visualise operational data.
Log Analytics and KQL Fundamentals is a free Cloud & IT Cert Prep lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Cloud & IT Cert Prep learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What Is a Log Analytics Workspace?
A Log Analytics workspace is the central data store in Azure Monitor for log and telemetry data. When you configure diagnostic settings on an Azure resource, the structured logs and metrics flow into the workspace. You can then query the data using the Kusto Query Language (KQL). A workspace has its own retention policy (default 30 days, up to 730 days) and access controls.
# Create a Log Analytics workspace
az monitor log-analytics workspace create \
--resource-group myRG \
--workspace-name myWorkspace \
--location eastus \
--retention-time 90Sending Diagnostic Logs to a Workspace
Every Azure resource can emit diagnostic logs — detailed records of operations such as API calls, authentication events, and query execution. You enable them through Diagnostic Settings on the resource, specifying the destination as your Log Analytics workspace. Common log categories include AuditEvent for Key Vault, AppServiceHTTPLogs for App Service, and NetworkSecurityGroupFlowEvent for NSGs.
# Enable diagnostic settings to send Key Vault logs to Log Analytics
az monitor diagnostic-settings create \
--name 'KVLogs' \
--resource /subscriptions/<sub>/resourceGroups/myRG/providers/Microsoft.KeyVault/vaults/myKV \
--workspace myWorkspace \
--logs '[{"category":"AuditEvent","enabled":true}]'Introduction to KQL Syntax
Kusto Query Language (KQL) is a read-only query language for analysing log data. A KQL query reads left-to-right as a pipeline: start with a table name, then pipe (|) through operators. Common operators include where for filtering, project for selecting columns, summarize for aggregation, and order by for sorting. KQL is case-sensitive for column names but not for keywords.
// Basic KQL query structure
AzureActivity
| where TimeGenerated > ago(24h)
| where OperationNameValue == 'MICROSOFT.COMPUTE/VIRTUALMACHINES/DELETE'
| project TimeGenerated, Caller, ResourceGroup, Resource
| order by TimeGenerated descFiltering with the Where Operator
The where operator filters rows using boolean expressions. You can combine conditions with and, or, and not. The has operator performs case-insensitive word-boundary search in strings, while contains does a substring search. The in operator tests membership in a list. Use ago() to express relative time ranges like ago(1h) or ago(7d).
// Filter for failed HTTP requests in the last hour
AppRequests
| where TimeGenerated > ago(1h)
| where Success == false
| where ResultCode in (500, 502, 503)
| project TimeGenerated, Name, ResultCode, DurationMs
| order by DurationMs descAggregating Data with Summarize
The summarize operator computes aggregations across rows. Common aggregation functions include count(), sum(), avg(), max(), min(), and dcount() for distinct count. You can group by one or more columns using the by clause. The bin() function rounds timestamps to intervals for time-series aggregation.
// Count failed requests per hour per endpoint
AppRequests
| where TimeGenerated > ago(24h)
| where Success == false
| summarize FailureCount = count() by bin(TimeGenerated, 1h), Name
| order by TimeGenerated desc, FailureCount descJoining Tables in KQL
KQL supports join to correlate data from multiple tables. The default join kind is innerunique but you can specify inner, leftouter, rightouter, or fullouter. A common pattern is joining AzureActivity with AzureMetrics to correlate administrative changes with performance dips. The lookup operator is a lighter-weight alternative for enriching rows from a small reference table.
// Correlate VM restarts with CPU spike events
AzureActivity
| where OperationNameValue has 'restart'
| join kind=leftouter (
AzureMetrics
| where MetricName == 'Percentage CPU'
| where Average > 90
) on ResourceId
| project TimeGenerated, Resource, AverageVisualising KQL Results
After writing a query in the Log Analytics portal, you can render results as a time chart, bar chart, pie chart, or table using the render operator. You can also pin any query result to an Azure Dashboard or save it as a Workbook. The render timechart command turns a time-series summarize query into an instant line chart for trend analysis.
// Render a time chart of request counts per 5-minute interval
AppRequests
| where TimeGenerated > ago(4h)
| summarize RequestCount = count() by bin(TimeGenerated, 5m)
| render timechartLog Search Alerts
Log search alerts run a KQL query on a schedule and fire when the result meets a condition, such as result count greater than zero or a numeric column exceeding a threshold. They are more flexible than metric alerts because you can query any log data across multiple tables. Evaluation frequency and time window are independently configurable — for example, run every 5 minutes over the last 15 minutes.
// Example log search alert condition: more than 5 exceptions in 15 min
AppExceptions
| where TimeGenerated > ago(15m)
| summarize ExceptionCount = count()
// Alert when ExceptionCount > 5Common Log Tables Reference
Azure Monitor stores logs in well-known tables. AzureActivity records subscription-level operations. SecurityEvent contains Windows Security logs from VMs with the Log Analytics agent. Heartbeat shows agent connectivity (one row per minute per connected VM). AppRequests, AppExceptions, and AppDependencies come from Application Insights. Knowing these table names is essential for writing effective operational queries.
Workspace Retention and Costs
Log Analytics pricing has two components: data ingestion (per GB ingested) and data retention (first 30 days are free, then charged per GB per month beyond the default). You can reduce costs by filtering noisy log categories before ingestion, using Basic Logs for high-volume low-value data at a reduced price, and archiving older data to Azure Data Explorer or cold storage for long-term compliance retention.
Workspace Access Control Models
Log Analytics workspaces support two access control models. In workspace-context mode, a user with Read access to the workspace can query all tables. In resource-context mode, a user can query only the logs emitted by resources they have RBAC permission to read — even without explicit workspace access. Resource-context mode is recommended for large organisations where different teams own different resources.
Quick Check
Test your understanding of Microsoft Azure Fundamentals (AZ-900) concepts from this lesson.
Lesson Recap
In this lesson you learned: Log Analytics workspaces centralise diagnostic log data from Azure resources, KQL operators like where, summarize, and render let you filter, aggregate, and visualise logs, and log search alerts trigger automated responses when a KQL query result meets a defined condition. Next up we explore Application Insights for application-level telemetry.
Frequently asked questions
Is the “Log Analytics and KQL Fundamentals” lesson free?
Yes — the full text of “Log Analytics and KQL Fundamentals” is free to read here on the web, and the Cloud & IT Cert Prep course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Cloud & IT Cert Prep course, upgrade to CoddyKit PRO.
What will I learn in “Log Analytics and KQL Fundamentals”?
Ingest diagnostic logs into a Log Analytics workspace and write Kusto Query Language queries to filter, aggregate, and visualise operational data. You practise Cloud & IT Cert Prep with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Cloud & IT Cert Prep?
No prior experience is required. Cloud & IT Cert Prep on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Log Analytics and KQL Fundamentals” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Cloud & IT Cert Prep lesson?
Yes. Every Cloud & IT Cert Prep lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Azure Monitor Metrics and Alerts
- Log Analytics and KQL Fundamentals
- Application Insights
- Azure Dashboards and Workbooks