2013-02-19 68 views
2


我一直在寫日誌寫入物理磁盤上的文件,但我注意到TimeGenerated屬性的奇怪行爲 - 計算機上的本地日期是xx.xx.2056(不要問爲什麼),但財產的價值xx.xx.1920年和時間不匹配。

下面是代碼:
EventLogEntry.TimeGenerated返回完全錯誤的日期

using (EventLog log = new EventLog("Application", ".")) 
{ 
    using (StreamWriter sw = new StreamWriter("events.log")) 
    { 
     foreach (EventLogEntry e in log.Entries) 
     { 
      sw.WriteLine("{0} : {1} : {2}", e.TimeGenerated, e.EntryType, e.Message); 
     } 
    } 
} 


在此先感謝。

+0

我要問.... *爲什麼*是本地日期2056 ?是不太知名的UTC + 375k時區? – 2013-02-19 06:27:19

+0

我們正在測試我們的應用程序以瞭解它如何工作,我想它被稱爲未來日期測試或類似的東西。那麼,我可以用2056年不遠的其他一年,但它仍然會給我同樣的結果。 – cookieMonster 2013-02-19 06:32:36

+0

此問題是否與特定日期範圍有關?或者不管它總是發生? – bytefire 2013-02-19 06:35:01

回答

0

測試上WIN2003服務器SP2,本地日期2056(正確的日期在事件查看器):

  ManagementScope ms = new ManagementScope(); 
      ObjectQuery oQuery = new ObjectQuery("Select * from Win32_NTLogEvent where Logfile = 'Application' and type ='Error'"); 
      ManagementObjectSearcher oS = new ManagementObjectSearcher(ms, oQuery); 
      ManagementObjectCollection oCollection = oS.Get(); 
      var i2 = oCollection.Cast<ManagementObject>().First(); 
      DateTime timewritten = ManagementDateTimeConverter.ToDateTime(i2["TimeWritten"].ToString()); 

我得到1920

+0

這是如何回答這個問題的? – ryadavilli 2013-02-19 07:58:20