Check Event Source Existance and Create Event Source : Event Log « Windows « C# / C Sharp






Check Event Source Existance and Create Event Source



using System;
using System.Diagnostics;

class MainClass {
    public static void Main() {
        if (!EventLog.SourceExists("C#")) {
            EventLog.CreateEventSource("C#", "Application");
        }

        EventLog.WriteEntry(
            "C#",                          // Registered event source
            "A simple test event.",        // Event entry message
            EventLogEntryType.Information, // Event type
            1,                             // Application-specific ID
            0,                             // Application-specific category
            new byte[] { 10, 55, 200 }       // Event data
        );
    }
}
           
       








Related examples in the same category

1.Write Message to system event logWrite Message to system event log
2.Get first 5 message from system event log
3.Write the Event Log Entry type as Information
4.Specify EventLogEntryType
5.Removes the registration for an event source if it has been registered