我正在使用C#代碼從eventviewer日誌文件中獲取特定錯誤的錯誤消息。如何使用c#從EventViewer日誌中獲取最新的錯誤細節?
static void Main(string[] args)
{
EventLog myLog = new EventLog();
myLog.Log = "Application";
myLog.Source = "Application Error";
foreach (System.Diagnostics.EventLogEntry entry in myLog.Entries)
{
if (entry.TimeGenerated == DateTime.Parse("9/19/2016 11:48:58 AM"))
{
using (StreamWriter writer = File.AppendText("Example.txt"))
{
writer.WriteLine(error_Message);
}
}
}
這是我的主要功能,其中我在我的應用程序日誌中獲取特定錯誤的錯誤消息,我打印的文本文件中的錯誤消息。因此,我不想使用日期時間訪問錯誤,我想訪問日誌文件中的最新錯誤。如何獲取日誌文件中最後輸入的錯誤?提前致謝。
沒有得到爲什麼當你想要最後的錯誤信息時,你正在共同映射時間戳。 –