3
Windows Server 2008 R2에서이 문제가 발생했습니다.EventLog.EntryWritten 이벤트가 지난 이벤트를 처리합니다.
사용자 지정 응용 프로그램 로그가 있으며 이름을 "MyCustomLog"로 지정할 수 있습니다.이 이벤트 로그는 분당 수백 개의 항목을받습니다. 그들 중 일부는 경고 또는 오류입니다.
왜 그런 일이 않습니다 ... 나는 이전의 일 정도의 이벤트를 의미, 시간 EntryWritten
에
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);
}
}
}
는 과거의 이벤트를 처리 : 나는 이벤트를 인쇄하는 간단한 콘솔 응용 프로그램을 만들었습니다? 내가 뭘 놓치고 있니?
업데이트
: 여기 응용 프로그램의 출력 예입니다 : 당신의 OnEntryWritten 기능에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>