• 3 min read

Simplifying Virtual Machine Troubleshooting using Azure Log Collector

This post provides information on using the Azure Log Collector extension for collecting Virtual Machine and Cloud Service logs.

Have you run into a scenario where something has gone wrong with your virtual machine or with your cloud service application and you have to collect logs from different role/VM instances for troubleshooting? What if you cannot connect to the Virtual Machine to collect these logs? To address these  scenarios, the Azure Customer Support team has released the Azure Log Collector extension which can collect and upload logs from Cloud Service instances or Virtual Machines without requiring to log into the remote Virtual Machine!   These logs can be automatically uploaded to Azure storage which can be shared with Azure support team or anyone who is troubleshooting the issue. If you're new to VM Extensions, you can get overview of VM Extensions by visiting the documentation site here .

Note: The current version of Log Collector targets windows VMs only, Linux support would be coming soon.

Why do we need the Log Collector extension?

When you are working on troubleshooting issues with your application deployed to either the Azure PaaS or IaaS platform, you need to collect diagnostics data from the virtual machines at the exact time when the problem happened. The data could be generated from your own service or from Azure components such as Azure VM Agent. It needs some in-depth knowledge of Azure environment to find and collect the right data.  Azure Log Collector simplifies this by supporting the following:

  • A simple command line interface for log collection with support for customization.
  • No dependency on remote access connection, the diagnostics data will still be collected even Remote Access is not enabled or stops working for any reason.
  • The extension can be enabled from anywhere using Service Management REST API or Azure PowerShell cmdlets.
  • If your cloud services have many role instances, the extension saves significant time to get log data from all virtual machines using a single sequence of commands at once.
  • It allows you to specify custom locations on VMs to collect any additional data files.
  • It works with both Virtual Machines and Cloud Services.


What log files does the Extension collect?

The collection modes supported by Azure Log Collector are as follows:

Type Logs Collected
Azure Platform Logs This collection mode includes all the logs related to Azure guest agents and other Azure components
All Logs
  • Azure Platform Logs
  • System and application event logs
  • HTTP error logs
  • IIS Logs
  • Setup logs
  • And other system logs
Additional Logs Any custom log folder can be targeted for collection .

Please refer to VM Extension documentation for information on configuring these two modes and the blog here for description of files to be collected by this extension.

How to use the Azure Log Collector Extension?

Depending on whether you are troubleshooting cloud service or an application running inside Azure Virtual Machine, the documentation provides two sample PowerShell scripts called  ‘SetAzureServiceLogCollector.ps1’ and  ‘SetAzureVMLogCollector.ps1’  , copy these scripts and run them locally by following the instructions in the documentation page.  After that, collecting logs is as simple as below: Sample use case for Azure VM.

#Specify your cloud service name
$ServiceName = 'YourServiceName'

#Specify the instances on which extension will be installed and enabled.  Use wildcard * for all instances
$VMName = "YourVMName"

#Specify the additional data collection folders and settings
$AdditionalDataList = @()

#Specify the collection mode, "Full" or "GA"
$mode = "Full"
$StorageAccountName = 'Your Azure Storage Account Name'
$StorageAccountKey = 'Your Storage Key'
.SetAzureServiceLogCollector.ps1 -ServiceName YourCloudServiceName  -Roles $roles  -Instances $instances –Mode $mode -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey -AdditionDataLocationList $AdditionalDataList

Similarly, here is a sample use case for Azure Cloud Service

.SetAzureServiceLogCollector.ps1 -ServiceName YourCloudServiceName  -Roles $roles  -Instances $instances –Mode $mode -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey -AdditionDataLocationList $AdditionalDataList

Note: These two scripts can be copied from the documentation page. Repeat the commands again to collect logs multiple times. Depending on log and the VM size, it could take up to a few minutes to get the logs uploaded to the storage account.

What happens after the logs are collected?

Once the logs are uploaded to the storage account, they can be inspected for troubleshooting by following the steps here or can be send to Azure Support team if there is a support incident. If the extension is no longer needed, the extension can be uninstalled using the MSDN documentation. Here is the sample code for IaaS VMs.: For IaaS :

Get-AzureVM -ServiceName $ServiceName -Name $VMName | Set-AzureVMExtension -Publisher Microsoft.WindowsAzure.Compute -ExtensionName "AzureLogCollector" -Version 1.0 -Uninstall | Update-AzureVM -Verbose

We hope you find this extension useful ! Stay tuned for the Linux version of this and the custom cmdlet support for adding the extension!