As we have seen in my previous blog some diagnostics data is stored in a table, while some in a blob. For collecting diagnostics data, we must initialize the Windows Azure diagnostic monitor. The Windows Azure diagnostic monitor runs in Windows Azure and in the computer's emulator and collects diagnostic data for a role instance. Only Windows Azure Logs, Windows Azure Diagnostic Infrastructure Logs and IIS logs are configured in the diagnostic monitor by default. We can collect other diagnostic data by importing a diagnostic module. When a role instance that imports the Diagnostic module starts, it starts the diagnostic monitor.
To start the diagnostic monitor for a role open the role entry point class and make sure that you are using the Microsoft.WindowsAzure.Diagnostics namespace in the class. Now on the Azure service project right click on the role and click Properties. Here I am configuring a web role.
Now in the configuration section check "Enable Diagnostics". And specify the account credentials.
You can either use development storage or can give your account credentials. Just click on "...." and it will ask for the credentials.
Now when you open your .cscfg file it has a new setting for the webrole like:
<ConfigurationSettings>
<Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="DefaultEndpointsProtocol=https;AccountName=myaccountName;AccountKey=myAccountKey" />
</ConfigurationSettings>
And in the .csdef file it imports the module like:
<Imports>
<Import moduleName="Diagnostics" />
</Imports>
If you are using a web role or worker role template for creating roles then in the web.config or app.config the following code is added. Or you can just inherit a class from RoleEntryPoint and add the following code in the config file. If you want to create a web role just override the OnStart() method, and if you want to create a web role override OnStart() and Run() method.
<system.diagnostics>
<trace>
<listeners>
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
<filter type="" />
</add>
</listeners>
</trace>
</system.diagnostics>