iT邦幫忙

DAY 3
2

程式隨手寫系列 第 3

(2)

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中,並把資料由系統中刪除


上一篇
2
下一篇
想不到標題(3)
系列文
程式隨手寫20
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中
0
csk
iT邦高手 1 級 ‧ 2013-10-03 16:39:23

這標題也太炫了吧!

0
Ken(Bigcandy)
iT邦大師 1 級 ‧ 2013-10-03 18:10:36

iT邦幫忙MVPcsk提到:
這標題也太炫了吧!

這標題也太簡單了吧~~
噎到

月半車甫 iT邦研究生 3 級 ‧ 2013-10-03 19:01:01 檢舉

被太炫的標題騙進來哈哈

0
一級屠豬士
iT邦大師 1 級 ‧ 2013-10-03 19:08:50

王牌大賤諜裡的Number2

0
temo
iT邦新手 1 級 ‧ 2013-10-04 12:42:25

汗想不出該寫什麼標題.....

我要留言

立即登入留言