在迁移到2.0之前,下面的代码工作(类型CloudStorageAccount在名称空间StorageClient中):
CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(
RoleEnvironment.GetConfigurationSettingValue(wadConnectionString));
var roleInstanceDiagnosticManager = cloudStorageAccount.CreateRoleInstanceDiagnosticManager(
RoleEnvironment.DeploymentId,
RoleEnvironment.CurrentRoleInstance.Role.Name,
RoleEnvironment.CurrentRoleInstance.Id);
在2.0中删除了StorageClient,所以现在我必须使用
Microsoft.WindowsAzure.Storage.CloudStorageAccount
,此类型没有CreateRoleInstanceDiagnosticManager
方法那么我怎样才能获得CreateRoleInstanceDiagnosticManager先前返回的实例,因为我将它用于我的性能计数器和日志
答案 0 :(得分:5)
看起来肯定有2.0的变化,并且不再像扩展方法那样 - 这意味着你可能不需要你在顶部拥有的CloudStorageAccount我自己也遇到了这个。
试试这个:
CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(
RoleEnvironment.GetConfigurationSettingValue(wadConnectionString));
var roleInstanceDiagnosticManager = CloudAccountDiagnosticMonitorExtensions.CreateRoleInstanceDiagnosticManager(
RoleEnvironment.GetConfigurationSettingValue(wadConnectionString),
RoleEnvironment.DeploymentId,
RoleEnvironment.CurrentRoleInstance.Role.Name,
RoleEnvironment.CurrentRoleInstance.Id);
答案 1 :(得分:0)
您所做的首先包括以下名称空间:
using Microsoft.WindowsAzure.Diagnostics.Management;
然后使用以下代码:
CloudStorageAccount cloudStorageAccount =
cloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue
(wadConnectionString));
RoleInstanceDiagnosticManager roleInstanceDiagnosticManager =
cloudStorageAccount.CreateRoleInstanceDiagnosticManager
(RoleEnvironment.DeploymentId,
RoleEnvironment.CurrentRoleInstance.Role.Name,
RoleEnvironment.CurrentRoleInstance.Id);
我刚用SDK 1.8& Storage Client 2.0。
答案 2 :(得分:0)
它不起作用,因为 CreateRoleInstanceDiagnosticManager 扩展名引用旧的 CloudStorageAccount 。解决方法是使用 DeploymentDiagnosticManager
var storageConnectionString = RoleEnvironment.GetConfigurationSettingValue(
"Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString");
var deploymentDiagnosticManager = new DeploymentDiagnosticManager(
storageConnectionString,
RoleEnvironment.DeploymentId);
return deploymentDiagnosticManager.GetRoleInstanceDiagnosticManager(
RoleEnvironment.CurrentRoleInstance.Role.Name,
RoleEnvironment.CurrentRoleInstance.Id);`
除了 Microsoft.WindowsAzure.Storage 之外,您需要引用旧的 Microsoft.WindowsAzure.StorageClient ,因为AzureDiagnostics引用该程序集。