Home > Articles > Programming > Windows Programming

  • Print
  • + Share This
Like this article? We recommend Setting Up Windows Azure Diagnostics

Setting Up Windows Azure Diagnostics

The Windows Azure Diagnostics API supports the standard .NET classes such as those that support tracing, performance counters, event logs, and IIS logs. The enhancements allow you to collect data from multiple role instances and store them in Azure tables and blobs. Once that's done, you don't care whether your application moves to another virtual machine, because the data that was in the filesystem of the virtual machine is now in durable storage. All the information from your various roles is stored in one place. You can also modify what you're monitoring without a service upgrade (that is, reinstalling your application).

Figure 1 illustrates how this works.

Figure 1 Diagnostics configuration.

Your role instance saves the monitoring data to the local directory storage just as it would in a non-cloud application. IIS logs, PerfMon counters, and event logs are stored in their normal locations, as are traces, logs, and crash dumps. All the monitoring and diagnostic classes that you know how to use work exactly as they did previously.

What's new is the Diagnostic Monitor. When your role instance starts, you supply the Diagnostic Monitor with the monitoring data you want to save to Azure storage, and you indicate how frequently you want it saved. With the periodicity specified, the Diagnostic Monitor pulls the diagnostic information out of the local filesystem and saves it in Azure table and blob storage.

The following code fragment from a WebRole's OnStart method illustrates how this works:

public override bool OnStart()
    DiagnosticMonitorConfiguration c = DiagnosticMonitor.GetDefaultInitialConfiguration();

    c.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1);
    c.Logs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;
     DiagnosticMonitor.Start(diagnosticConnectionString, c);
     return base.OnStart();

The code gets the Diagnostic Monitor's initial configuration, modifies it to save trace information up to the verbose level every minute, and then saves the revised configuration. The remainder of the code works with tracing just as it would in a non-cloud application.

  • + Share This
  • 🔖 Save To Your Account