Skip to content
Get Started for Free

Diagnostic Setting

Azure Monitor Diagnostic Settings configure where a resource sends its platform logs and metrics. Supported destinations include Log Analytics Workspaces, Storage Accounts, Event Hubs, and partner solutions. Diagnostic settings are commonly used to enable centralized log collection and compliance auditing across Azure deployments. For more information, see Diagnostic settings in Azure Monitor.

LocalStack for Azure provides a local environment for building and testing applications that make use of Azure Monitor Diagnostic Settings. The supported APIs are available on our API Coverage section, which provides information on the extent of Diagnostic Settings’ integration with LocalStack.

This guide uses the existing monitor.mdx article workflow as a reference. See also the Monitor page for a broader overview of diagnostic settings alongside activity log examples.

Launch LocalStack using your preferred method. For more information, see Introduction to LocalStack for Azure. Once the container is running, enable Azure CLI interception by running:

Terminal window
azlocal start-interception

This command points the az CLI away from the public Azure management REST API and toward the LocalStack for Azure emulator API. To revert this configuration, run:

Terminal window
azlocal stop-interception

This reconfigures the az CLI to send commands to the official Azure management REST API.

Create a resource group to hold all resources created in this guide:

Terminal window
az group create --name rg-diag-demo --location westeurope
Output
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-diag-demo",
"location": "eastus",
"name": "rg-diag-demo",
"properties": { "provisioningState": "Succeeded" },
"type": "Microsoft.Resources/resourceGroups"
}

Create a storage account as the destination

Section titled “Create a storage account as the destination”

Create a storage account to serve as the export destination for the logs and metrics:

Terminal window
az storage account create \
--name sadiagdemo \
--resource-group rg-diag-demo \
--location westeurope \
--sku Standard_LRS
Output
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-diag-demo/providers/Microsoft.Storage/storageAccounts/sadiagdemo",
"kind": "StorageV2",
"location": "eastus",
"name": "sadiagdemo",
"resourceGroup": "rg-diag-demo",
"sku": { "name": "Standard_LRS", "tier": "Standard" },
"type": "Microsoft.Storage/storageAccounts"
...
}

The following example creates a diagnostic setting on a storage account (nested blob service) that routes StorageRead logs to a storage account:

Terminal window
RESOURCE_ID="/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-diag-demo/providers/Microsoft.Storage/storageAccounts/sadiagdemo/blobServices/default"
DEST_ID="/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-diag-demo/providers/Microsoft.Storage/storageAccounts/sadiagdemo"
az monitor diagnostic-settings create \
--name my-diag-setting \
--resource "$RESOURCE_ID" \
--storage-account "$DEST_ID" \
--logs '[{"category": "StorageRead", "enabled": true}]' \
--metrics '[{"category": "Transaction", "enabled": true}]'
Output
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-diag-demo/providers/Microsoft.Storage/storageAccounts/sadiagdemo/blobServices/default/providers/microsoft.insights/diagnosticSettings/my-diag-setting",
"logs": [ { "category": "StorageRead", "enabled": true } ],
"metrics": [ { "category": "Transaction", "enabled": true } ],
"name": "my-diag-setting",
"storageAccountId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-diag-demo/providers/Microsoft.Storage/storageAccounts/sadiagdemo",
"type": "microsoft.insights/diagnosticSettings"
...
}

List all diagnostic settings attached to the target resource:

Then list all diagnostic settings to confirm the setting was removed:

Terminal window
az monitor diagnostic-settings list --resource "$RESOURCE_ID"
Output
{
"value": [
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-diag-demo/providers/Microsoft.Storage/storageAccounts/sadiagdemo/blobServices/default/providers/microsoft.insights/diagnosticSettings/my-diag-setting",
"logs": [ { "category": "StorageRead", "enabled": true } ],
"metrics": [ { "category": "Transaction", "enabled": true } ],
"name": "my-diag-setting",
"storageAccountId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-diag-demo/providers/Microsoft.Storage/storageAccounts/sadiagdemo",
"type": "microsoft.insights/diagnosticSettings"
}
]
...
}

Retrieve the full configuration of the diagnostic setting:

Terminal window
az monitor diagnostic-settings show \
--name my-diag-setting \
--resource "$RESOURCE_ID"
Output
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-diag-demo/providers/Microsoft.Storage/storageAccounts/sadiagdemo/blobServices/default/providers/microsoft.insights/diagnosticSettings/my-diag-setting",
"logs": [ { "category": "StorageRead", "enabled": true } ],
"metrics": [ { "category": "Transaction", "enabled": true } ],
"name": "my-diag-setting",
"storageAccountId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-diag-demo/providers/Microsoft.Storage/storageAccounts/sadiagdemo",
"type": "microsoft.insights/diagnosticSettings"
...
}

Update the setting to also route to an Event Hub (stored, not routed):

Terminal window
az monitor diagnostic-settings update \
--name my-diag-setting \
--resource "$RESOURCE_ID" \
--logs '[{"category": "StorageRead", "enabled": false}]'
Output
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-diag-demo/providers/Microsoft.Storage/storageAccounts/sadiagdemo/blobServices/default/providers/microsoft.insights/diagnosticSettings/my-diag-setting",
"logs": [ { "category": "StorageRead", "enabled": false } ],
"metrics": [ { "category": "Transaction", "enabled": true } ],
"name": "my-diag-setting",
"storageAccountId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-diag-demo/providers/Microsoft.Storage/storageAccounts/sadiagdemo",
"type": "microsoft.insights/diagnosticSettings"
...
}

Delete the resource and confirm it no longer appears in the list:

Terminal window
az monitor diagnostic-settings delete \
--name my-diag-setting \
--resource "$RESOURCE_ID"

Then list all diagnostic settings to confirm the setting was removed:

Terminal window
az monitor diagnostic-settings list --resource "$RESOURCE_ID"
Output
[]
  • Diagnostic setting lifecycle: Create, read, list, update, and delete diagnostic settings on any resource.
  • Multiple destinations: Accept Storage Account, Log Analytics Workspace, and Event Hub as destinations.
  • Log category configuration: Enable or disable individual log categories per setting.
  • Metric category configuration: Enable or disable individual metric categories per setting.
  • Retention policy support: Accept retention day settings per log and metric category.
  • Resource-scoped settings: Settings are scoped to a specific resource (by resource ID).
  • No data routing: Logs and metrics are not routed to the configured Storage Account, Log Analytics Workspace, or Event Hub. The setting is stored in the emulator only.
  • No log ingestion: Platform logs emitted by Azure services within LocalStack are not captured or forwarded.
  • No subscription diagnostic settings: The subscription-level diagnostic settings endpoint (PUT /subscriptions/{id}/providers/microsoft.insights/diagnosticSettings) is not currently supported.

The following sample demonstrates how to use Azure Diagnostic Settings with LocalStack for Azure:

OperationImplemented
Page 1 of 0
Was this page helpful?