How do I configure Azure Monitor Diagnostic Logging with the Azure Portal or Powershell?

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

  1. Go to the Azure portal and select the resource for which you want to configure diagnostic settings.
  2. In the left-hand menu, under Monitoring, select Diagnostic settings.
  3. On the Diagnostic settings page, click on Add diagnostic setting.
  4. In the Add diagnostic setting blade, enter a name for the diagnostic setting.
  5. Under Categories, select the categories of logs that you want to collect.
  6. Under Destination details, select the destination for your logs (e.g. Log Analytics workspace or storage account).
  7. Configure the settings for the destination you have chosen.
  8. Click Save to save the diagnostic setting.

Using Azure PowerShell

  1. Install the Azure PowerShell module on your local machine if you haven’t already.
  2. Open PowerShell and sign in to your Azure account using the Connect-AzAccount cmdlet.
  3. 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
  1. $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 the Get-AzOperationalInsightsWorkspace and Get-AzSqlDatabase cmdlets. Then, we create a new diagnostic setting using the New-AzDiagnosticSetting cmdlet and set the workspace ID and enabled flag. Finally, we use the Set-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.

Author: tonyhughes