如何更改 Azure SDK 2.5 中每个服务配置的诊断存储位置

How to change diagnostics storage location per service configuration in Azure SDK 2.5

在 Azure SDK 2.5 中,存储帐户在角色的 wadcfgx 中设置如下:

<PrivateConfig xmlns="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration">
<StorageAccount name="myDiagnosticAccount" endpoint="https://core.windows.net/" />

问题是我想为暂存和生产使用单独的诊断帐户。像这样:

用于分期

<PrivateConfig xmlns="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration">
<StorageAccount name="myProductionDiagStorageAccount" endpoint="https://core.windows.net/" />
</PrivateConfig>

并用于生产

<PrivateConfig xmlns="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration">
<StorageAccount name="myStageDiagStorageAccount" endpoint="https://core.windows.net/" />
</PrivateConfig>

但我看不到任何可能的方法来执行此操作,因为此配置是按角色而不是按服务配置的。在之前的 SDK 中,我曾设置两个不同的诊断连接字符串 - “Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString” - 一切正常。

现在如何在 SDK 2.5 中实现这一点?

你是对的。使用 SDK 2.5,无法为不同的部署环境定义不同的存储帐户。

一种可能性是保留两个单独的诊断配置文件(一个用于暂存,另一个用于生产)。您需要在部署期间禁用诊断,一旦部署了代码,您可以使用 Set-AzureServiceDiagnosticsExtension Cmdlet 启用诊断。

事实上,这似乎是基于此博客 post 的推荐方法:http://blogs.msdn.com/b/kwill/archive/2014/12/02/windows-azure-diagnostics-upgrading-from-azure-sdk-2-4-to-azure-sdk-2-5.aspx(请参阅标题为 Enabling diagnostics extension through PowerShell 的部分)。来自博客 post:

Since Azure SDK 2.5 uses the extension model the diagnostics extension, the configuration and the connection string to the diagnostic storage are no longer part of the deployment package and cscfg. All the diagnostics configuration is contained within the wadcfgx. The advantage with this approach is that diagnostics agent and settings are decoupled from the project and can be dynamically enabled and updated even after your application is deployed.

Due to this change some existing workflows need to be rethought – instead of configuring the diagnostics as part of the application that gets deployed to each environment you can first deploy the application to the environment and then apply the diagnostics configuration for it. When you publish the application from Visual Studio this process is done automatically for you. However if you were deploying your application outside of VS using PowerShell then you have to install the extension separately through PowerShell.

更新 - 2015 年 5 月 26 日

SDK 2.6 实际上支持不同部署环境的不同存储帐户。来自 release notes:

The Diagnostics storage account can now be specified in the service configuration (.cscfg) file making it easier to use different diagnostics storage accounts for different environments.

如果您已经在使用 SDK 2.5,我建议您将其升级到 SDK 2.6。