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

时间:2016-12-02 14:05:41

标签: azure azure-cloud-services azure-diagnostics

我根本不想要PowerShell。我可以很好地创建云服务,并将诊断配置文件作为工作者角色根目录的一部分。你怎么打开扩展名呢?

1 个答案:

答案 0 :(得分:2)

发现了自己。

        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"
                  }}
            }

        });