Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
Windows Azure

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

10/11/2012 6:16:49 PM
- How To Install Windows Server 2012 On VirtualBox
- How To Bypass Torrent Connection Blocking By Your ISP
- How To Install Actual Facebook App On Kindle Fire

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
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us
Popular tags
Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 windows Phone 7 windows Phone 8
programming4us programming4us
 
programming4us
Natural Miscarriage
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Game Trailer