Wednesday, November 28, 2007

How to write to the Event Viewer

from http://support.microsoft.com/kb/307024

using System.Diagnostics;

...
WriteToEventViewer("MOSS-CRM Webservice", "Application", "User provided is invalid");

...

private void WriteToEventViewer(string sSource, string sLog, string sEvent)
{
if (!EventLog.SourceExists(sSource))

EventLog.CreateEventSource(sSource, sLog);

EventLog.WriteEntry(sSource, sEvent, EventLogEntryType.Warning, 234);
}

Also:

System.Diagnostics.EventLog eventLog = new System.Diagnostics.EventLog("Application");

eventLog.Source = "Rtws";

eventLog.WriteEntry(ex.ToString(), System.Diagnostics.EventLogEntryType.Error);




end

No comments: