In this video, learn how to enable diagnostic logs using the Azure Monitor and PowerShell.
- [Instructor] Diagnostic logs for your resources, can be enabled from the resource itself. The Azure Monitor, PowerShell, the command-line interface, Azure Monitor REST API or from within a template. And keep in mind, not all resources can have diagnostic logs enabled. We are going to enable diagnostic logs from the Azure Monitor which I'm already in. You'll have to scroll down to settings to find diagnostic settings. Next, we can go ahead and select our subscriptions or subscription.
I'm gonna ahead and load more, because I know there's more resources that we can leverage here. We can filter on resource group which I'm going to do. And you'll notice that we have three resources selected. And again you can filter on these as required. I'm going to leave it as is. We're going to go ahead and enable diagnostic logs for DemoVM-ip, and go ahead and select it, and then turn on the log.
The first thing you'll need to do is provide a name. And our diagnostic logs can be sent to any of the three locations. We can archive them to a storage account, we can stream them to an event hub or send them to Log Analytics for further analysis. For our demonstration, we're gonna go ahead and archive them to storage. Next, we have to go ahead and configure the storage account. I already have a storage account prepared called diagnosticlogsdemo.
I'm gonna go ahead and select that. Next, we can go ahead and select the log and the metric. Go ahead and click Save, and that's all there is for capturing diagnostic logs from within the portal. Now, let's use the same procedure, but we'll do it via PowerShell. The command that that will use in PowerShell to enable diagnostic logging is, Set-AzureRmDiagnosticSetting and then our ResourceId, and I scroll all the way over, cause you'll notice how long that ResourceId is.
And in this case, we're gonna select the virtual machine DC. Next, enabled will be true, and then we have to provide the StorageAccountId as well. And again, you'll notice that that is a very long ID. Before we run that command, I'm gonna show you how we get those IDs. And to do so, you'll simply use the command, Get-AzureRmResource and then you'll pipe it to ft. And this is how you can retrieve that ResourceId .
Let's go ahead and run the Set-AzureRmDiagnosticSetting command Now, let's go ahead and view that setting, and we're simply going to use the command, Get Set-AzureRmDiagnosticSetting, and then ResourceId one more time. And if I scroll up, we can see the metrics are now enabled and our TimeGrain is set to the default PT1 Minute, and the logs are also enabled again using the default TimeGrain PT1M.
If I want to disable the diagnostics on this resource, we'll use the set command one more time, and it will be set Set-AzureRmDiagnosticSetting, our ResourceId enabled will equal false. I'll go ahead and run that. And to verify that worked, we'll go back to the Get-AzureRmDiagnosticSetting, and we can see our metric is now at false as is the logs.
- Managing Azure subscriptions and resources
- Implementing and managing storage
- Configuring and managing virtual networks
- Managing identities
- Evaluating and performing server migration to Azure
- Implementing and managing application services
- Implementing advanced virtual networking
- Securing identities