2011-10-21 43 views
9

使用下面的代碼,我能夠顯示在「應用程序」中列出的所有條目記錄:事件日誌 - 獲取可用的日誌

EventLog appLog = new EventLog(); 
appLog.Log = "Application"; 
appLog.MachineName = "."; 

foreach (EventLogEntry entry in appLog.Entries) 
{ 
// process 
} 

由於我必須與服務器的任何FTPØRDP訪問,是有什麼辦法可以在「應用程序」旁邊獲得所有可用日誌的列表?某些日誌是標準的,但新的可以由用戶/應用程序添加。

回答

9

運行:

var d = EventLog.GetEventLogs(); 
     foreach(EventLog l in d) 
     { 
      Console.WriteLine(l.LogDisplayName); 
     } 

如果你想看到所有的名。它們存儲在一個數組中。

編輯: 做的工作,你有它設置使用方式:

var d = EventLog.GetEventLogs(); 
     foreach(EventLog l in d) 
     { 
      foreach (EventLogEntry entry in l.Entries) 
      { 
       // process 
      } 
     } 
+0

謝謝,非常完美! – jdecuyper