我在 Windows Server 2008 R2 上遇到了这个问题。
我有一个自定义应用程序日志,我们将其命名为“MyCustomLog”,此事件日志每分钟接收数百个条目。其中一些是警告或错误。我创建了简单的控制台应用程序来打印事件:
class Program
{
static void Main(string[] args)
{
EventLog eventLog = new EventLog("MyCustomLog", Environment.MachineName);
eventLog.EntryWritten += new EntryWrittenEventHandler(OnEntryWritten);
eventLog.EnableRaisingEvents = true;
Console.ReadLine();
}
private static void OnEntryWritten(object sender, EntryWrittenEventArgs e)
{
if (e.Entry.EntryType == EventLogEntryType.Error
|| e.Entry.EntryType == EventLogEntryType.Warning)
{
Console.WriteLine();
Console.WriteLine("Now Date:" + DateTime.Now);
Console.WriteLine("Received:" + e.Entry.TimeWritten);
Console.WriteLine(e.Entry.Message);
}
}
}
不时EntryWritten
处理过去的事件,我的意思是前一天左右的事件......
为什么会发生?我错过了什么?
更新:这是应用程序输出的示例:
Now Date:2013-10-02 15:05:04
Received:2013-10-01 10:20:02
<Some Data>
Now Date:2013-10-02 15:05:04
Received:2013-10-01 10:20:08
<Some Data>
Now Date:2013-10-02 15:05:04
Received:2013-10-01 10:20:49
<Some Data>
Now Date:2013-10-02 15:05:04
Received:2013-10-01 10:20:54
<Some Data>