如何仅使用Microsoft.WindowsAzure.Management库将诊断添加到azure云服务?

如何仅使用Microsoft.WindowsAzure.Management库将诊断添加到azure云服务?,azure,azure-cloud-services,azure-diagnostics,Azure,Azure Cloud Services,Azure Diagnostics,我根本不想让PowerShell卷入其中。我可以创建云服务,并且我的诊断配置文件是worker角色根目录的一部分。你怎么打开分机呢?我自己发现了 var etcs = cloudClient.HostedServices.ListAvailableExtensions(); var et = etcs.FirstOrDefault(p => p.Type == "PaaSDiagnostics"); cloudClient.Hos

我根本不想让PowerShell卷入其中。我可以创建云服务,并且我的诊断配置文件是worker角色根目录的一部分。你怎么打开分机呢?

我自己发现了

        var etcs = cloudClient.HostedServices.ListAvailableExtensions();

        var et = etcs.FirstOrDefault(p => p.Type == "PaaSDiagnostics");





        cloudClient.HostedServices.AddExtension("agent1", new Microsoft.WindowsAzure.Management.Compute.Models.HostedServiceAddExtensionParameters()
        {
            Type = et.Type,
            ProviderNamespace = et.ProviderNameSpace,
            Id = "testext",
            Version = et.Version,
            PublicConfiguration = File.ReadAllText(@"PubConfig.xml"),
            PrivateConfiguration = "<?xml version=\"1.0\" encoding=\"utf-8\"?><PrivateConfig xmlns=\"http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration\"><StorageAccount name=\"store\" key=\"" + ks.SecondaryKey + "\"></StorageAccount></PrivateConfig>"


        });



        var id = cloudClient.Deployments.Create("agent1", Microsoft.WindowsAzure.Management.Compute.Models.DeploymentSlot.Production, new Microsoft.WindowsAzure.Management.Compute.Models.DeploymentCreateParameters()
        {
            Name = "test",
            Configuration = File.ReadAllText(@"ServiceConfiguration.Cloud.cscfg"),
            PackageUri = blob.Uri,
            Label = "Test",
            StartDeployment = true,
            ExtensionConfiguration = new Microsoft.WindowsAzure.Management.Compute.Models.ExtensionConfiguration()
            {
                AllRoles = new[] { new Microsoft.WindowsAzure.Management.Compute.Models.ExtensionConfiguration.Extension ()
                  {
                       Id = "testext",
                        State = "Enable"
                  }}
            }

        });
var etcs=cloudClient.HostedServices.ListAvailableExtensions();
var et=etcs.FirstOrDefault(p=>p.Type==“PaaSDiagnostics”);
cloudClient.HostedServices.AddExtension(“agent1”,新的Microsoft.WindowsAzure.Management.Compute.Models.HostedServiceAddExtensionParameters()
{
类型=等类型,
ProviderNamespace=et.ProviderNamespace,
Id=“testext”,
版本=等版本,
PublicConfiguration=File.ReadAllText(@“PubConfig.xml”),
PrivateConfiguration=“”
});
var id=cloudClient.Deployments.Create(“agent1”,Microsoft.WindowsAzure.Management.Compute.Models.DeploymentSlot.Production,新的Microsoft.WindowsAzure.Management.Compute.Models.DeploymentCreateParameters()
{
Name=“test”,
Configuration=File.ReadAllText(@“ServiceConfiguration.Cloud.cscfg”),
PackageUri=blob.Uri,
Label=“测试”,
StartDeployment=true,
ExtensionConfiguration=新的Microsoft.WindowsAzure.Management.Compute.Models.ExtensionConfiguration()
{
AllRoles=new[]{new Microsoft.WindowsAzure.Management.Compute.Models.ExtensionConfiguration.Extension()
{
Id=“testext”,
State=“启用”
}}
}
});