升级到 Window Azure 2.5 时出现问题

Problems in upgrading to Window Azure 2.5

我尝试通过创建一个新的 Azure 云服务项目从 1.8 升级到 Window Azure SDK 2.5。但是在部署到 Azure Cloud 时出错:

Your role instances have recycled a number of times during an update or upgrade operation. This indicates that the new version of your service or the configuration settings you provided when configuring the service prevent the role instances from running. Verify your code does not throw unhandled exceptions and that your configuration settings are correct and then start another update or upgrade operation.

Azure SDK 1.8 中的旧 azure 项目运行良好。在本地调试时,我在 WebRole.cs 中崩溃(在 SDK 1.8 中创建)。错误信息是:

An exception of type 'System.NullReferenceException' occurred in OTP.Ring.Web.dll but was not handled in user code

发生在:

diagnosticsConfig.Logs.ScheduledTransferPeriod = TimeSpan.FromSeconds(60);

所以我觉得WebRole.cs应该改一下,大概涉及到WindowsAzure.Diagnostics。我需要有关如何更改 WebRole.cs 的帮助。其代码如下:

   public class WebRole : RoleEntryPoint
    {
        public override bool OnStart()
        {
            var diagnosticsConfig = DiagnosticMonitor.GetDefaultInitialConfiguration();

            diagnosticsConfig.Logs.ScheduledTransferPeriod = TimeSpan.FromSeconds(60);
            if (ExtensionMethods.GetConfigurationSetting("loggingLevel") == Common.Logger.LogType.ERROR.ToString())
            {
                diagnosticsConfig.Logs.ScheduledTransferLogLevelFilter = LogLevel.Error;
            }
            else if (ExtensionMethods.GetConfigurationSetting("loggingLevel") == Common.Logger.LogType.DIAGNOSTIC.ToString())
            {
                 diagnosticsConfig.Logs.ScheduledTransferLogLevelFilter = LogLevel.Warning;
            }
            DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", diagnosticsConfig);

            Logger.LogDiagnostic("Starting WebRole");

            // For information on handling configuration changes
            // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
            RoleEnvironment.Changing += RoleEnvironmentChanging;

            return base.OnStart();
        }

        private void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e)
        {
            // If a configuration setting is changing
            if (e.Changes.Any(change => change is RoleEnvironmentConfigurationSettingChange))
            {
                // Set e.Cancel to true to restart this role instance
                e.Cancel = true;
            }
        }
    }

请注意,从 SDK 2.5 开始不再支持基于代码的诊断配置。这在 SDK 2.5 发行说明中提到:https://msdn.microsoft.com/en-us/library/azure/dn873976.aspx(请参阅 Breaking Changes 部分)。我相信您因此而收到错误。

我建议的另一件事是将您的解决方案升级到 SDK 2.6 而不是 2.5。 SDK 2.6 于上月底发布,解决了 2.5 中发现的一些问题。