To configure Azure Monitor Diagnostic Logging, you can use either the Azure portal or Azure PowerShell. Here are the steps for both:
Using Azure Portal
- Go to the Azure portal and select the resource for which you want to configure diagnostic settings.
- In the left-hand menu, under Monitoring, select Diagnostic settings.
- On the Diagnostic settings page, click on Add diagnostic setting.
- In the Add diagnostic setting blade, enter a name for the diagnostic setting.
- Under Categories, select the categories of logs that you want to collect.
- Under Destination details, select the destination for your logs (e.g. Log Analytics workspace or storage account).
- Configure the settings for the destination you have chosen.
- Click Save to save the diagnostic setting.
Using Azure PowerShell
- Install the Azure PowerShell module on your local machine if you haven’t already.
- Open PowerShell and sign in to your Azure account using the
Connect-AzAccount
cmdlet. - To configure diagnostic logging for a resource, use the
Set-AzDiagnosticSetting
cmdlet. For example, to configure diagnostic logging for an Azure SQL database, you can run the following command:bash
$workspace = Get-AzOperationalInsightsWorkspace -ResourceGroupName "<resource group name>" -Name "<workspace name>" $database = Get-AzSqlDatabase -ResourceGroupName "<resource group name>" -ServerName "<server name>" -DatabaseName "<database name>" $settings = New-AzDiagnosticSetting -Name "<setting name>" -WorkspaceId $workspace.ResourceId -Enabled $true Set-AzDiagnosticSetting -ResourceId $database.ResourceId -DiagnosticSettings $settings
In this example, we first get the workspace and database resources using theGet-AzOperationalInsightsWorkspace
andGet-AzSqlDatabase
cmdlets. Then, we create a new diagnostic setting using theNew-AzDiagnosticSetting
cmdlet and set the workspace ID and enabled flag. Finally, we use theSet-AzDiagnosticSetting
cmdlet to apply the diagnostic setting to the database resource.
Once you have configured diagnostic logging, you can view the logs in the destination that you have selected.