In this blog, I will demonstrate new diagnostics features of the new SDK (April 2012, v2.0) in a sample application. All the diagnostics instrumentation will be done on built-in features by modifying configuration settings. This is well aligned with “Configure before Customize” approach.
Requirements:
- Windows Azure SDK v2.0, Windows Azure .NET Developer Center. This includes azure emulators (compute and storage) as well.
- Storage Explorer (Optional): Azure Storage Explorer tool from NEUDESIC, http://azurestorageexplorer.codeplex.com/.
- Azure cloud service, please refer to this link http://www.windowsazure.com/en-us/manage/services/cloud-services/
- Azure storage account, please refer to this link http://www.windowsazure.com/en-us/manage/services/storage/
- And an IDE, I am using Visual Studio (VS) 2012.
The Solution
Ok, time to run the cloud service. Then browse the Task page where some dummy traces are passed to listener as sampled just above this.
Where are the Logs?
All the diagnostics logs are written to files in "C:\Users\[your_user_account]\AppData\Local\” path. Please note, you need change your folder settings, since the AppData is hidden. Here, DevelopmentStorage and dftmp folder are the locations where all the application related logs are written.
From the folder above, the logs matching selected log level (Error by default) are persisted into the storage table (WADLogsTable, etc). To see the entries, you can use different tools (storage explorer, etc.), I am going to use VS for this purpose as well. To do that, click on View on VS’ top menu, then Server Explorer (or Ctrl + W). On the Server Explorer panel, click on Windows Azure Storage then Development (local run), then Tables and "WADLogsTable" (storage table name).
How it works?
As you can see, diagnostics are already enabled for both web and worker roles. If you look at the web.config in the web application, you will see that a trace listener called 'AzureDiagnostics' also added (web role and the associated web application runs on different processes).
You can see that from GUI as well by right click on a role then Properties:
Now, we know the reason why error-type logs are written only, because, by default, it is set to 'Errors only'. Diagnostics settings here are reflected in the diagnostics configuration file called 'diagnostics.wadcfg'.
How-to Change Settings
Now, if you want to change the settings, please follow the steps picture below:
(1): Role diagnostics configuration window
For example, when I change log level to Information and enable both Event and Performance counters logs, I am able to see all the logs (except Verbose) for application, performance and events, as seen below:
And you can change the setting while your application running (alive!)
Time for deployment:
Please note that before going to deploy the solution, in regards to diagnostics feature context and the image (1) - "Role diagnostics configuration window" above:
- You need to update storage account accordingly. You should use a separate diagnostic storage table for PROD environment
- Set the log level for errors initially, when troubleshooting, you can set the level accordingly depending on implemented diagnostics features on your application (Information, Verbose, etc.).
- Set the buffer size and transfer intervals (less buffer/interval means, less amount of data and more often data transfer from the local folder to storage table. Please refer this link fore more details: http://msdn.microsoft.com/en-us/library/windowsazure/dn186185.aspx.