Saturday, June 27, 2009

How to wirte errors in EventViewer?

// logText will be the message to write in Event veiwer.
public static void WriteLog(string logText)
{

using (EventLog myLog = new EventLog("Application"))
{
// Create an EventLog instance and assign its source.
myLog.Source = "Application Name";

// Write an informational entry to the event log.
myLog.WriteEntry(logText, EventLogEntryType.Error);
}
}