Perform an On-Demand Transfer
Updated: December 2, 2013
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
Log on to the portal.
Click Compute Services, and then expand the node for your application.
Click the deployment for the application.
Record the ID value from the Properties pane. This is the deployment identifier of your hosted service.
Expand the deployment node, and then click the node for the role from which you want to collect diagnostic data.
Record the Name value from the Properties pane. This is the name of the role.
Expand the role node, and then click the node for the role instance.
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
Open the source file for the program you are using to perform the transfer.
Ensure that the project references the Microsoft.WindowsAzure.Diagnostics.dll file and that the following using statements are added to the file:
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 Configuring Windows Azure Connection Strings.
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:
Where <DeploymentID> is the value that you obtained in the previous procedure.
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.
Specify the logs that you want to transfer. The following code example shows how to transfer the Windows Azure logs:
For information about the data buffers that can be added, see DataBufferName.
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.
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: