First, MSDN is your friend. Make sure you check out the link, as there are some potential gotchas worth knowing.
Essentially, you create an EventLog object:
this.ServiceName = "MyService";
this.EventLog = new System.Diagnostics.EventLog();
this.EventLog.Source = this.ServiceName;
this.EventLog.Log = "Application";
You also need to create a source, if the above source doesn't exist:
((ISupportInitialize)(this.EventLog)).BeginInit();
if (!EventLog.SourceExists(this.EventLog.Source))
{
EventLog.CreateEventSource(this.EventLog.Source, this.EventLog.Log);
}
((ISupportInitialize)(this.EventLog)).EndInit();
and then simply use it:
this.EventLog.WriteEntry("My Eventlog message.", EventLogEntryType.Information);
it's actually pretty simple.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…