2013-02-07 4 views
1

다음 코드를 실행할 때 2/feb/12의 출력을 실행하면 오늘 날짜와 어제, 그 다음날 어제 전 출력을 표시하려고합니다.C에서 역순으로 이벤트 출력을 표시하는 방법은 무엇입니까?

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); 
      } 
     } 
    } 
} 

답변

2

Reverse에 대한 간단한 호출을 할 것입니다 .... 내가이 문제를 해결하기 위해 도와주세요 :

그 옵션을 사용할 미안하지
foreach (var log in eventLog.Entries.Cast<EventLogEntry>().Reverse()) {...} 
+0

, 다른 – Gomathipriya

+0

을 제안 할 수 있습니다 @ Gomathipriya Answer 업데이트 됨 - Reverse 메서드가'IEnumerable '에서 사용 가능합니다. Cast 를 호출하면이 메서드를 사용할 수 있습니다. –

+0

해결책 감사합니다. – Gomathipriya

관련 문제