gpt4 book ai didi

azure - WindowsEventLogs 未登录到 Azure

转载 作者:行者123 更新时间:2023-12-03 01:57:43 24 4
gpt4 key购买 nike

我有一个包含以下代码的 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);
}

在我的 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);
}

出于某种原因,如果我在 Debug模式下运行该代码并在 OnStart 方法上设置断点并使用 F11 运行代码,则该代码可以正常工作。但是,如果删除所有断点并运行它,我在 WADWindowsEventLogsTable 中看不到任何 EventLog 条目。所以这对我来说似乎是一个计时问题...有谁知道为什么我的代码执行此行为?

提前致谢!

最佳答案

问题出在 EventLog.WriteEntry() 方法上。我使用源“TestClass”作为事件日志源。但是,我从未使用启动任务创建此源,并且由于权限不足,它无法记录我的条目。

因此解决方案:使用启动任务创建自己的源或使用跟踪消息。

关于azure - WindowsEventLogs 未登录到 Azure,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10735396/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com