Write to an Event Log using C#

Event logging provides a standard, centralized way for your applications to record important software and hardware events.

string eventSource, strlog, message;

eventSource = “YasserSource”;
strlog = “LogDetails”;
message = “This is my error message”;

// Creates an event source if it does not exists
if (!EventLog.SourceExists(eventSource)) {
EventLog.CreateEventSource(eventSource,strlog);
}

EventLog.WriteEntry(eventSource, message, EventLogEntryType.Error);

Be sure you include System.Diagnostics;