Logo
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
EPL Standings
 
 
Windows Azure

Azure Monitoring and Diagnostics : Logging config data in our application, Transferring and persisting diagnostic data

10/11/2012 6:16:49 PM

Logging config data in our application

Now that we have the collection of diagnostic data configured, we need to add code to our application to send diagnostic data to the listeners. We can do this simply by making calls to the methods in the System.Diagnostics.Trace class (documented at http://msdn.microsoft.com/en-us/library/36hhw2t6.aspx).

One of the more common methods we'll call is Trace.Writeline, as seen here:

Trace.Writeline("An error has occurred!","Error")

If our filter is set to the value Error or higher, our message would be logged. An alternative, easier syntax is:

Trace.TraceError("An error has occurred!")

Again, if our filter is set to the value Error or higher, our message will be logged. The simplified methods are limited to TraceError, TraceInformation, and TraceWarning, whereas the WriteLine method can be used to log diagnostic data at any level, including custom levels.

Transferring and persisting diagnostic data

As diagnostic data are logged, the data are buffered in memory. In order for us to retain the data for analysis, we need to make sure that the data persists in a proper storage container. This is not set up by default, but it takes only a couple of lines of code to configure the transfer of data into the storage location. We can set this transfer to be either scheduled, or on demand.

To automatically transfer the diagnostic data on a schedule, we just need to add a single line to our role's OnStart method:

diagConfig.PerformanceCounters.ScheduledTransferPeriod = System.TimeSpan.FromMinutes(1.0)


					  

The entire OnStart method for our web role now reads like this:

Public Overrides Function OnStart() As Boolean
OnStart methodDim diagConfig As DiagnosticMonitorConfiguration = DiagnosticMonitor.GetDefaultInitialConfiguration()
Dim procTimeConfig As PerformanceCounterConfiguration = New PerformanceCounterConfiguration()
procTimeConfig.CounterSpecifier = "\Processor(*)\% Processor Time"
procTimeConfig.SampleRate = System.TimeSpan.FromSeconds(1.0)
diagConfig.PerformanceCounters.DataSources.Add(procTimeConfig)
diagConfig.PerformanceCounters.ScheduledTransferPeriod = System.TimeSpan.FromMinutes(1.0)
DiagnosticMonitor.Start("DiagnosticsConnectionString")
Return MyBase.OnStart()
End Function


					  

We'll need to add similar code to the OnStart methods of the other roles in our application if we want to automatically transfer the diagnostic logs for those roles too.

An on-demand transfer is a little different an on-demand transfer can be initiated either from within the role, from another role in the same application, or even a completely different application. To reduce the amount of diagnostic data we need to sort through when debugging, we might want to log every level of diagnostic data but transfer the diagnostic data only when an error occurs.

Public Sub TransferDiagnosticData()
Dim diagManager As DeploymentDiagnosticManager = New DeploymentDiagnosticManager(<Azure storage account name>, <Azure deployment ID>)
dim roleInstDiagMgr as RoleInstanceDiagnosticManager = diagManager.GetRoleInstanceDiagnosticManager( <Role name>, <Role instance name>)
Dim dataBuffersToTransfer As DataBufferName = DataBufferName.Directories
Dim transferOptions As OnDemandTransferOptions = New OnDemandTransferOptions()
With transferOptions
.From = DateTime.MinValue
.To = DateTime.UtcNow
End With
Dim requestID As Guid = roleInstDiagMgr.BeginOnDemandTransfer(dataBuffersToTransfer, transferOptions)
End Sub


					  

Complete documentation for transferring buffered data to storage can be found at http://msdn.microsoft.com/en-us/library/ee830425.aspx.

It's important to note that diagnostic data is treated the same as any other data associated with our application, and we will be charged for the storage of the diagnostic output.

Other -----------------
- Azure Monitoring and Diagnostics : Azure Diagnostics­ under the hood, Enabling diagnostic logging
- Web Services and Azure : Our WCF web services
- Web Services and Azure : Creating a new WCF service web role
- Azure Blob Storage : Windows Azure Content Delivery Network, Blob Storage Data Model
- Azure Blob Storage : Blobs in the Azure ecosystem, Creating Blob Storage
- The Nickel Tour of Azure : How are Azure costs calculated?
- The Nickel Tour of Azure : Explaining Azure to the managers
- Application Life Cycle Management
- Sharing Digital Photographs : Exploring Photo-Sharing Communities
- Sharing Digital Photographs : Exploring Online Photo-Editing Applications
- Surfacing SQL Azure Data in Bing Maps by Using the Client Object Model
- Storing and Sharing Files and Other Online Content : Exploring Online Bookmarking Services
- Storing and Sharing Files and Other Online Content : Understanding Cloud Storage & Evaluating Online File-Storage and -Sharing Services
- Integrating the SharePoint Server Object Model and the Entity Data Model (part 2) - Create a Meeting Scheduler Visual Web Part
- Integrating the SharePoint Server Object Model and the Entity Data Model (part 1) - Create a Console Application to Write Data to a SharePoint List
- Collaborating on Presentations : Evaluating Web-Based Presentation Applications (part 2)
- Collaborating on Presentations : Evaluating Web-Based Presentation Applications (part 1)
- Securing the Connection to SQL Azure (part 3) - Surface SQL Azure Data in a Visual Web Part
- Securing the Connection to SQL Azure (part 2) - Set Permissions for an External Content Type
- Securing the Connection to SQL Azure (part 1) - Create an Application ID & Create an External Content Type
 
 
Most view of day
- Microsoft Excel 2010 : Calculating the Mode (part 1)
- What's new and improved in SharePoint 2013 : Creating a new site
- Microsoft Visio 2010 : Working with Text (part 2) - Editing and Formatting Text
- BizTalk 2010 : ASDK SQL adapter examples (part 4) - Composite Operations
- Microsoft Exchange Server 2010 : Managing Message Pickup, Replay, Throttling, and Back Pressure (part 1) - Configuring and Moving the Pickup and Replay Directories
- Windows Phone 8 : Orientation and the PhoneApplicationPage Class (part 3) - Setting Page Orientation at Runtime
- Microsoft Dynamics AX 2009 : Form Customization (part 1) - Learning Form Fundamentals
- Sharepoint 2013 : Create a Subsite
- Microsoft Visio 2010 : Creating and Validating Process Diagrams - Reusing Existing Validation Rules
- Using Application Deployment Tools : Deploying Applications Using RDS (part 1) - Deploying RemoteApp Applications
Top 10
- Windows Server 2012 : DHCP,IPv6 and IPAM - Exploring DHCP (part 3) - Creating IPv4 DHCP Scopes
- Windows Server 2012 : DHCP,IPv6 and IPAM - Exploring DHCP (part 2) - Installing DHCP Server and Server Tools
- Windows Server 2012 : DHCP,IPv6 and IPAM - Exploring DHCP (part 1)
- Windows Server 2012 : DHCP,IPv6 and IPAM - Understanding the Components of an Enterprise Network
- Microsoft OneNote 2010 : Using the Research and Translate Tools (part 3) - Translating Text with the Mini Translator
- Microsoft OneNote 2010 : Using the Research and Translate Tools (part 2) - Translating a Word or Phrase with the Research Pane
- Microsoft OneNote 2010 : Using the Research and Translate Tools (part 1) - Setting Options for the Research Task Pane, Searching with the Research Task Pane
- Microsoft OneNote 2010 : Doing Research with Linked Notes (part 2) - Ending a Linked Notes Session, Viewing Linked Notes
- Microsoft OneNote 2010 : Doing Research with Linked Notes (part 1) - Beginning a Linked Notes Session
- Microsoft OneNote 2010 : Doing Research with Side Notes (part 3) - Moving Side Notes to Your Existing Notes
 
 
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
2015 Camaro