1

当我执行以下代码时,它执行 12 年 2 月 2 日的输出,我想显示今天的输出,然后是昨天,然后是前天。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace @event
{
    using System.Diagnostics;
    class MySample
    {
        public static void Main()
        {
            string eventLogName = "System";
            string sourceName = "BTHUSB";
            string machineName =".";
            EventLog eventLog;
            eventLog = new EventLog();
            eventLog.Log = eventLogName;
            eventLog.Source = sourceName;
            eventLog.MachineName = machineName;
            int i;
            i = 0;

            foreach (EventLogEntry log in eventLog.Entries)
            {
                i = i + 1;
                if(log.EntryType.ToString()=="Error")
                Console.WriteLine((i)+") Entry type: {0} , Category: {1},  Data: {2}, ID: {3}, Source: {4} \n",log.EntryType,log.TimeWritten.ToLocalTime(),log.Data,log.EventID,log.Source);
            }
        }
    }
}

请帮我解决这个问题....

4

1 回答 1

2

一个简单的Reverse调用就可以做到:

foreach (var log in eventLog.Entries.Cast<EventLogEntry>().Reverse()) {...}
于 2013-02-07T11:44:53.243 回答