Enable and retrieve AzureWebsite Diagnostics logs using PowerShell

In this article, I am going to show how to enable AzureWebsite diagnostic logs using PowerShell. An AzureWebsite supports both Web Server logs and custom application logs. We can identify IIS level request and response information using Web Server logs. Using custom application logs, we can write custom trace messages to track the code flow. We are also going to see how to retrieve these logs for a particular AzureWebsite using PowerShell.

To get started, download and install last Microsoft Azure PowerShell – May 2015 release. Once installed, login to Azure Subscription in PowerShell by following this tutorial. We can create a new AzureWebsite and publish an ASP.Net MVC website (created in Visual Studio 2013) to created AzureWebsite by following this tutorial.

Use below command from Azure PowerShell, to enable application logs for an AzureWebsite.

 Enable-AzureWebsiteApplicationDiagnostic -File -LogLevel Information -Name intstringsdemo 


In above command, we have mentioned that logs should be written to File System. AzureWebsites also supports writing logs to Azure Storage either in Tables or Blobs. To enable Azure storage blobs, we have to give either –BlobStorage or –TableStorage in above command instead of –File. We also need to specify Storage Account and Container names, where we want our logs to be stored.

NOTE: we can enable all there logs (File, Blob and Tables) and configure them to handle different log levels.

We can also specify log level with following options – Error, Information, Warning and Verbose. Lets say we have following code in Home Controller and Index Action –

 public ActionResult Index()
      Trace.TraceWarning("This is warning");
      Trace.TraceError("This is Error");
      Trace.TraceInformation("This is Information");

      return View();

To stream an AzureWebsite log, we can run following command.

 Get-AzureWebsiteLog -Name intstringsdemo -Tail 



In the above command, –Tail specifies to stream the logs to PowerShell console. We can also use –Message to filter logs based on a string, and –Path can be used to specify the path where logs are present (default path is root where all logs are stored).

We can enable Detailed Error logging, using following command. Detailed Error logging will have information of http errors (having status code 400 or above).

 Set-AzureWebsite -DetailedErrorLoggingEnabled $true -Name intstringsdemo 

Request tracing should be enabled to identify all the failed HTTP requests. By enabling request tracing, we can get to know the complete flow of all IIS components and can easily identify at which point request was failed. We can enable Request tracing by using below command.

 Set-AzureWebsite -RequestTracingEnabled $true -Name intstringsdemo 

Finally web server logging can be enabled using below command. Web server logging will cover overall site metrics.

 Set-AzureWebsite -HttpLoggingEnabled $true -Name intstringsdemo 

NOTE: To disable Web Server, Detailed Error and Request Tracing Logging, we can use above commands with value being set to false.

To save logs on remote machine, we can execute following command.

 Save-AzureWebsiteLog -Output 'C:\Users\venvemula\Desktop\logs.zip' -Name intstringsdemo 



Above command will create a file logs.zip and will save it the location specified in the output.


Application logs can be found under Application folder, similarly Detailed Errors as well. Web server logs can be found under http –> RawLogs folder. Failed Request Tracing logs (XML files) will be present in a folder which starts with “W3SVC” (that folder is not present in the above screenshot).

We can disable application logs, using below command.

 Disable-AzureWebsiteApplicationDiagnostic -File -Name intstringsdemo 

Thus we come to end of this article. In next set of tutorials we will find more about remote debugging, High availability of AzureWebsites etc., Stay tuned!!!

You may also like...