VB.NET, C#, PowerShellを使用しているエンジニアのためのサイト。
基本的な使用方法から開発で役立つTipsまで幅広く取り扱っています。
イベントログを取得するには、EventLog.Entriesプロパティでイベントログの内容を取得します。
サンプルではApplicationのログ5件を取得して、リストボックスへ表示します。
private void button1_Click(object sender, EventArgs e) { System.Diagnostics.EventLog evLog = new System.Diagnostics.EventLog("Application"); int iCnt = Math.Min(5, evLog.Entries.Count); for (int i = 0; i < iCnt; i++) { //イベントを発生させたアプリケーションを取得 listBox1.Items.Add(evLog.Entries[i].Source); //イベントに関連づけられたメッセージを取得 //listBox1.Items.Add(evLog.Entries(I).Message); } }