下面的代码在Azure开发结构中运行时会产生崩溃转储,但在我将其部署到云时则不会。我有:
但我仍然无法在存储帐户中找到任何内容。我使用VS 2010 Pro SP1瞄准.Net 4,并使用其内置的东西进行部署。我做错了什么?
public override void Run()
{
throw new ApplicationException("bugger");
}
public override bool OnStart()
{
ServicePointManager.DefaultConnectionLimit = 12;
DiagnosticMonitorConfiguration config = DiagnosticMonitor.GetDefaultInitialConfiguration();
string conn_str = RoleEnvironment.GetConfigurationSettingValue("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString");
CloudStorageAccount account = CloudStorageAccount.Parse(conn_str);
DiagnosticMonitor diagnosticMonitor = DiagnosticMonitor.Start(account, config);
CrashDumps.EnableCollection(true);
return base.OnStart();
}
这是我的配置:
<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="WindowsAzureProject1" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
<WorkerRole name="WorkerRole1">
<Imports>
<Import moduleName="Diagnostics" />
</Imports>
</WorkerRole>
</ServiceDefinition>
和
<?xml version="1.0" encoding="utf-8"?>
<ServiceConfiguration serviceName="WindowsAzureProject1" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="1" osVersion="*">
<Role name="WorkerRole1">
<Instances count="1" />
<ConfigurationSettings>
<Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="AccountName=XXX;AccountKey=XXX;DefaultEndpointsProtocol=https" />
</ConfigurationSettings>
</Role>
</ServiceConfiguration>
(我的真实项目 会产生崩溃转储,但我无法分析它们,这就是为什么我要尝试生成一个简化的示例。当它工作时我会看到它是否崩溃转储更好。)
编辑:部分解决方案是添加
config.Directories.ScheduledTransferPeriod = TimeSpan.FromMinutes(1);
创建了wad-crash-dumps blob容器,但不幸的是它仍然是空的。另请参阅my question about what happens to diagnostic data when a role fails。
答案 0 :(得分:1)
在抛出异常之前添加了Thread.Sleep(60000)。我认为发生的事情就是这样:
答案 1 :(得分:0)
我相信你错过了RoleInstanceDiagnosticManager。试着这样做:
DiagnosticMonitorConfiguration config = DiagnosticMonitor.GetDefaultInitialConfiguration();
string conn_str = RoleEnvironment.GetConfigurationSettingValue("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString");
CloudStorageAccount account = CloudStorageAccount.Parse(conn_str);
RoleInstanceDiagnosticManager roleInstanceDiagnosticManager = account.CreateRoleInstanceDiagnosticManager(RoleEnvironment.DeploymentId, RoleEnvironment.CurrentRoleInstance.Role.Name, RoleEnvironment.CurrentRoleInstance.Id);
CrashDumps.EnableCollection(true);
config.Directories.DataSources.Add(AzureLocalStorageTraceListener.GetLogDirectory());
config.Directories.ScheduledTransferPeriod = TimeSpan.FromMinutes(1);
config.ConfigurationChangePollInterval = TimeSpan.FromMinutes(5);
//set the configuration for use
roleInstanceDiagnosticManager.SetCurrentConfiguration(config);
RoleEnvironment.Changing += new EventHandler<RoleEnvironmentChangingEventArgs>(RoleEnvironment_Changing);
return base.OnStart();
答案 2 :(得分:0)
您是否有可能未设置ScheduledTransferPeriod和LogLevelFilter?
TimeSpan tsLogPeriod = TimeSpan.FromMinutes(double.Parse(RoleEnvironment.GetConfigurationSettingValue("LogIntervalInMinutes")));
DiagnosticMonitorConfiguration diagnosticMonitorConfiguration = DiagnosticMonitor.GetDefaultInitialConfiguration();
diagnosticMonitorConfiguration.Logs.ScheduledTransferPeriod = tsLogPeriod;
diagnosticMonitorConfiguration.Logs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;
DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", diagnosticMonitorConfiguration);
}