Click here to Skip to main content
15,884,628 members
Articles / Hosted Services / Azure

Enabling Diagnostics in Azure Cloud Services and Virtual Machines: Part 2

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
29 Sep 2014CPOL3 min read 6.9K   1  
In this post, we will take a look at the diagnostics.wadcfg configuration file, understanding the various sections it has.

In my previous post, we got familiar with the way Visual Studio provides us for setting up diagnostics for an Azure role. In this post we will take a look at the diagnostics.wadcfg configuration file, understanding the various sections it has.

Configuring Cloud Service Using diagnostics.wadcfg

Having configuration settings in the diagnostics.wadcfg has various advantages than configuring the diagnostics monitor programmatically. These are the advantages:

  • Roles OnStart() method is the earliest event in which we can configure diagnostics programmatically. But diagnostics processes start much before our roles OnStart method is called and our intended configuration are not applied at this point of time. But configuration in the diagnostics.wadcfg will be applied from the begining.
  • Any changes we make to the configuration at run time remains valid after a restart also. But handling configuration in code requires application rebuild and redeploy, for changes to take place.
  • In case of modifying existing configuration for a role in Azure cloud. If we have handled configuration in code, then it requires a role restart, to see the changes; whereas in case of changes to the XML configuration, we can avoid role restart in the RoleEnvironment.Changing event.

Whenever we add a role to a cloud project, the new template in Visual Studio adds the diagnostics.wadcfg by default under the role. And this configuration file holds all the settings for diagnostics. So whenever we configure the settings using Visual Studio, the settings get saved to this file. We can also manually add/edit this file, which we will be doing some time from now.

Diagnostics_1

In case you are still using the old template and upon creation of new role diagnostics.wadcfg configuration file is not getting added to your worker role. Then, you can follow the steps mentioned in the next section to add the configuration file. One thing to remember here is that whether we are working with a web / worker role, we will be following the same steps.

If we try to have the configuration file in both places, the configuration file associated with the role will always take higher precedence and can’t be removed also from the solution.

Adding diagnostics.wadcfg to a Worker Role

In order to add a configuration file, follow these steps:

  1. Add an XML file named as diagnostics.wadcfg to the root of your worker role.
  2. After successful addition, remove the repopulated contents of the new XML file and save it.
  3. The new file should be set to have the correct build properties, in order that the file is packaged correctly, during deployment. Now set the Build Action to Content and Copy to Output to a Copy always.

    Diagnostics_2_1

  4. If you try to type into the newly created XML file, you will see that IntelliSense does not work. In order to enable it, select the XML menu item present in Visual Studio and click on the Schemas menu item.

    Diagnostics_2_2

  5. This will open the XML Schemas window. Click the Add button, and in the resulting dialog, browse to the path of your XSD. It will be located at %ProgramFiles%\Microsoft SDKs\Windows Azure\.NET SDK\<VersionNumber>\schemas\DiagnosticsConfig201010.xsd, where <VersionNumber> is the Azure SDK version. Select the XSD and click OK.

    Diagnostics_2_3

  6. Now when you start typing in the XML file, you will have the XML support.

The only difference we have between the Visual Studio default created diagnostics.wadcfg and the one created manually. The Visual Studio created one has some configurations and the manual one has none. It’s ok, as we will be replacing the entire contents of the configuration file, with this.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer Mindfire Solutions
India India
Software developer, working at Mindfire Solutions, having hands on experience in both Windows and web application using C#, ASP.NET, ASP.NET MVC.

Comments and Discussions

 
-- There are no messages in this forum --