Perform an On-Demand Transfer in Azure Diagnostics

Note

This article only applies to Azure SDK 2.4 and below.

You can use the classes in Microsoft.WindowsAzure.Diagnostics.Management to perform an on-demand transfer of diagnostic data. An on-demand transfer can be completed from code running within a role, from another application running in Windows Azure, or from an application outside of Windows Azure. Before you complete the steps in this section, you must initialize the diagnostic monitor and specify the storage account to use. To do this, see Enabling Diagnostics in Windows Azure.

Obtain the deployment identifier, role name, and role instance name

If you are performing an on-demand transfer from code that runs outside of Windows Azure, you must obtain the deployment identifier, role name, and role instance name for your application by manually recording them from the portal.

To obtain the deployment identifier, role name, and role instance name

  1. Log on to the portal.

  2. Click Compute Services, and then expand the node for your application.

  3. Click the deployment for the application.

  4. Record the ID value from the Properties pane. This is the deployment identifier of your hosted service.

  5. Expand the deployment node, and then click the node for the role from which you want to collect diagnostic data.

  6. Record the Name value from the Properties pane. This is the name of the role.

  7. Expand the role node, and then click the node for the role instance.

  8. Record the Name value from the Properties pane. This is the identifier of the role instance.

Perform an on-demand transfer of diagnostic data

If you want to perform an on-demand transfer from within a running role, you can use properties of the RoleInstanceDiagnosticManager class.

To perform an on-demand transfer

  1. Open the source file for the program you are using to perform the transfer.

  2. Ensure that the project references the Microsoft.WindowsAzure.Diagnostics.dll file and that the following using statements are added to the file:

    using Microsoft.WindowsAzure.Diagnostics; 
    using Microsoft.WindowsAzure.Diagnostics.Management;
    
  3. Obtain the storage credentials from the configuration. The following code example shows how to use the Parse method to obtain the credentials:

    var storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=AccountName;AccountKey=<AccountKey>");
    

    For more information about using connection strings, see How to Configure Connection Strings.

  4. Create an instance of the DeploymentDiagnosticManager. The following code example shows how to create a new instance by using the storage account object and the deployment identifier:

    var diagManager = new DeploymentDiagnosticManager(storageAccount, "<DeploymentID>"); 
    

    Where <DeploymentID> is the value that you obtained in the previous procedure.

  5. Create a role instance diagnostic manager. The following code example shows how to create this diagnostic manager:

    var roleInstDiagMgr = diagManager.GetRoleInstanceDiagnosticManager("<RoleName>", "<RoleInstanceID>");
    

    Where <RoleName> and <RoleInstanceID> are the values that you obtained in the previous procedure.

  6. Specify the logs that you want to transfer. The following code example shows how to transfer the Windows Azure logs:

    DataBufferName dataBuffersToTransfer = DataBufferName.Logs;
    

    For information about the data buffers that can be added, see DataBufferName.

  7. Specify the transfer options. The following code example shows how to transfer entries from three hours ago to now:

    OnDemandTransferOptions transferOptions = new OnDemandTransferOptions();
    transferOptions.NotificationQueueName = "wad-on-demand-transfers";
    var timeInterval = new TimeSpan(3, 0, 0);
    transferOptions.From = DateTime.UtcNow.Subtract(timeInterval);
    transferOptions.To = DateTime.UtcNow;
    

    For more information about the transfer options, see OnDemandTransferOptions.

  8. Request that the data be transferred. The following code example shows how to start the transfer by using the data buffers and transfer options that were defined:

    Guid requestID = roleInstDiagMgr.BeginOnDemandTransfer(dataBuffersToTransfer, transferOptions);
    

See Also

Other Resources

Store and View Diagnostic Data in Azure Storage