using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Diagnostics;using KREventLogCls;namespace WriteLog...{ public partial class Form1 : Form ...{ public Form1() ...{ InitializeComponent(); } public void WriteLog(string sEvent) ...{ string sSource; string sLog; sSource = "mApp"; sLog = "mApplication"; KREventLogCls.KREventLogCls mWriteLog = new KREventLogCls.KREventLogCls(); if (!EventLog.SourceExists(sSource)) EventLog.CreateEventSource(sSource, sLog); //EventLog.Delete(sLog); EventLog.WriteEntry(sSource, sEvent); EventLog.WriteEntry(sSource, sEvent, EventLogEntryType.Warning, 234); } private void button1_Click(object sender, EventArgs e) ...{ try ...{ WriteLog("写入成功"); } catch (Exception ex) ...{ WriteLog("错误处理"); } finally ...{ } } }} 在事件查看器中可以看到刚才写入的信息.