Writing to EventLog

June 9th 2006 Event Log .NET Framework

Before using EventLog.WriteEntry for adding events to event log you should consider calling EventLog.CreateEventSource to make your application a valid source of events. Keep in mind though that you need administrative privileges for it to succeed, therefore it is best to call it at installation time. So, if you want to write to the application event log by calling:

EventLog.WriteEntry("MyApplicationName", "My event text");

don't forget doing this first:

if (!EventLog.SourceExists("MyApplicationName"))  
   EventLog.CreateEventSource("MyApplicationName", "Application");
Copyright
Creative Commons License