How to write entry in EventViewer using C#?

Hi all,

Just copy the following method in your project and call that method. It will write an entry in your EventViewer.

public void testEventLogEntry()

{

if (!System.Diagnostics.EventLog.SourceExists("MyTest.WinService"))

System.Diagnostics.EventLog.CreateEventSource(

"MyTest.WinService", "Application");

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

eventLog.Source = "MyTest.WinService";

eventLog.WriteEntry("Test");

}


...S.VinothkumaR.

No comments: