我有Azure WebRolle的代码如下:
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);
}
在我 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);
}
出于某种原因,如果我在 < code> OnStart 方法上用一个断点以调试模式运行该代码,并以 < kbd> F11 运行该代码,这个代码效果很好。 但是,如果我删除所有断点并运行它,我看不到我的 < strong> WADWindowsEventLogstable strong> 中的任何事件日志条目。 因此,这对我来说似乎是一个时间问题... 有人知道为什么我的代码要执行这个字句吗?
提前感谢!