10/28/09

Create Event Viewer Log with System.Diagnostics.EventLog



Here's some code that will log a message in an event viewer:


EventLog EventLog1 = new System.Diagnostics.EventLog();

if (!EventLog.SourceExists("Name"))
EventLog.CreateEventSource(
"Name", "Application");

EventLog1.Source = "Name";
EventLog1.WriteEntry(message.ToString(), EventLogEntryType.Error);

4 comments: