标准样例代码:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Diagnostics; using System.Diagnostics.Eventing; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string LogName = "Nieweiking_Log"; string SourceName = "Nieweiking的程序"; if (!EventLog.SourceExists(SourceName)) { var EventSourceData = new EventSourceCreationData(SourceName, LogName); EventLog.CreateEventSource(EventSourceData); } using (var log = new EventLog(LogName, ".", SourceName)) { log.WriteEntry("Message 1"); log.WriteEntry("Message 2", EventLogEntryType.Warning);; log.WriteEntry("Message 2", EventLogEntryType.Information, 33); } } } }