English 中文(简体)
WindowsEventLob 没有登录在 Azure 上
原标题:WindowsEventLogs not logged on Azure

我有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 中的任何事件日志条目。 因此,这对我来说似乎是一个时间问题... 有人知道为什么我的代码要执行这个字句吗?

提前感谢!

最佳回答

问题在于 < code> EventLog. writeEntry () 方法。 我使用源“ testClass” 作为事件Log 源。 但我从未以启动任务创建此源, 但由于权限不足, 它没有记录我的条目 。

所以解决方案: 创建一个有启动任务的源头, 或者使用跟踪信息 。

问题回答

当它被部署到阿祖尔时,这个角色是实际启动还是仅仅在初始化和繁忙之间循环?

如果问题与时间有关,则按时间将物品从例中转移到Azure存储处:

diagConfig.WindowsEventLog.ScheduledTransferPeriod = TimeSpan.FromMinutes(1D);

如果该实例在击中定时器之前重新启动,则没有东西被转到您的桌子上。





相关问题
Using EventLog objects can cause security holes?

While reading the Traning Guide for the 70-536 exam written by Tony Northup and friends, I came across the following: CAUTION - Avoid EventLog objects in partial trust environments Use of ...

Log errors in EventLog using ELMAH

I am using ELMAH to log errors in my asp.net MVC(C#) application. I am able to log errors in xml or database. How to log errors to the eventlog using ELMAH?

An event log source that s always available for writing?

Is there an event log source that s always available for writing by an ASP.NET webapp? Backstory, in case anyone has a seemingly unrelated solution: Our ASP.NET webapp uses its own event log source, ...

EventLog permission failing in ASP.Net on Win7

I have an ASP.Net app .net 3.5 SP1, running in Win7 . During the login process, something within the ASP.Net login control is causing a write to the security log (this sounds acceptable to me) in the ...

Unhandled IIS Exception - How can I track it down

I am seeing the following error in the event log. It is coming from our ASP.Net application. I am having trouble tracking down what is causing the error. Any suggestions appreciated! OS: Windows ...

What event id to use for my custom event log entries?

Is there any ranges of valid event IDs which should be used by custom applications while logging to Windows EventLog? Or I can use any event ID of my choice (1,2,3,4....). P.S, I am developing in C#....

way to "reverse" dw20.exe hashes?

Our application has been throwing unhandled exceptions. DW20.exe logs these like this test case: EventType clr20r3, P1 clr20r3.exe, P2 1.0.0.0, P3 4af175d6, P4 clr20r3, P5 1.0.0.0, P6 4af175d6, P7 1, ...

热门标签