private void Form1_Load(object sender, EventArgs e)
{
if (System.Diagnostics.EventLog.SourceExists("EreEventLog"))//判斷日誌位置
{
System.Diagnostics.EventLog.DeleteEventSource("EreEventLog");
}
System.Diagnostics.EventLog.CreateEventSource("EreEventLog", "Application");
eventLog2.Log = "Application"; //設置名稱
eventLog2.Source = "EreEventLog";//設置資料來源名稱
this.eventLog1.MachineName = ".";//設置讀取名稱
eventLog2.Clear();
}
private void button1_Click(object sender, EventArgs e)
{
if (eventLog1.Entries.Count > 0)//當日誌中有內容時
{
foreach (System.Diagnostics.EventLogEntry item in eventLog1.Entries)
{
if (item.EntryType == System.Diagnostics.EventLogEntryType.Error)
{
listBox1.Items.Add(item.Message); //把資料讀入listBox
eventLog2.WriteEntry(item.Message, System.Diagnostics.EventLogEntryType.Error);
}
}
}
else
MessageBox.Show("沒有錯誤日誌");
}
運用EventLog讀取系統日誌
把錯誤系統日誌寫入ListBox中,並把資料由系統中刪除
iT邦幫忙MVPcsk提到:
這標題也太炫了吧!
這標題也太簡單了吧~~
被太炫的標題騙進來