Using system;
Using system. diagnostics;
Using system. Threading;
Class mysample
{
Public static void main ()
{
// Create a log source to check whether the log source already exists
If (! EventLog. sourceexists ("My log source "))
{
// The log source of one time cannot be used immediately after creation.
// The recovery time is required to ensure that the log source has been created when the execution program uses the created log source.
// Run this example again to use the new log source.
EventLog. CreateEventSource ("My logs", "my logs ");
Console. WriteLine ("create event source ");
Console. WriteLine ("exiting, please run the program again to use the log source ");
// The log source has been created. Exit the program to allow it to be registered.
Return;
}
// Create an EventLog instance and allocate the log source.
EventLog myLog = new EventLog ();
MyLog. Source = "my log Source ";
// Write a report to the event log.
MyLog. WriteEntry ("Write Event Log ");
}
}