我有一个带有以下代码的 Azure WebRole:
public override bool OnStart()
{
setDiagnostics();
TestClass test = new TestClass();
return base.OnStart();
}
private void setDiagnostics()
{
string wadConnectionString = "Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString";
CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue(wadConnectionString));
DeploymentDiagnosticManager deploymentDiagnosticManager = new DeploymentDiagnosticManager(cloudStorageAccount, RoleEnvironment.DeploymentId);
RoleInstanceDiagnosticManager roleInstanceDiagnosticManager = cloudStorageAccount.CreateRoleInstanceDiagnosticManager(
RoleEnvironment.DeploymentId,
RoleEnvironment.CurrentRoleInstance.Role.Name,
RoleEnvironment.CurrentRoleInstance.Id);
DiagnosticMonitorConfiguration diagConfig = roleInstanceDiagnosticManager.GetCurrentConfiguration();
if (diagConfig == null)
diagConfig = DiagnosticMonitor.GetDefaultInitialConfiguration();
diagConfig.WindowsEventLog.DataSources.Add("Application!*");
diagConfig.WindowsEventLog.ScheduledTransferPeriod = TimeSpan.FromMinutes(1D);
roleInstanceDiagnosticManager.SetCurrentConfiguration(diagConfig);
DiagnosticMonitor.Start(wadConnectionString, diagConfig);
}
在 my 的构造函数中TestClass
是以下代码:
EventLog.WriteEntry("TestClass", "Before the try", EventLogEntryType.Information);
try
{
EventLog.WriteEntry("TestClass", "In the try", EventLogEntryType.Information);
Int32.Parse("abc");
}
catch (Exception ex)
{
EventLog.WriteEntry("TestClass", ex.Message, EventLogEntryType.Error);
}
OnStart
出于某种原因,如果我在调试模式下运行它并在方法上设置一个断点并使用F11. 但是,如果我删除所有断点并运行它,我不会在我的WADWindowsEventLogsTable中看到任何 EventLog 条目。所以这对我来说似乎是一个时间问题......有谁知道我的代码为什么会执行这种行为?
提前致谢!