Write the Event Log Entry type as Information : Event Log « Windows « C# / C Sharp






Write the Event Log Entry type as Information


 


using System;
using System.Diagnostics;

class MainClass {
    public static void Main() {
        string source = "EventSource";
        string log = "MainClass.LOG";

        EventLog el = new EventLog();

        if (!EventLog.SourceExists(source)) {
            EventLog.CreateEventSource(source, log);
        }
        el.Source = source;

        String message = "Starting Up";
        el.WriteEntry(message, EventLogEntryType.Information);
        message = "Processing";
        el.WriteEntry(message, EventLogEntryType.Information);
        message = "Shutting down";
        el.WriteEntry(message, EventLogEntryType.Information);

        el = new EventLog();

        if (!EventLog.SourceExists(source)) {
            Console.WriteLine("Event Log does not exist!");
            return;
        }
        el.Source = source;

        foreach (EventLogEntry entry in el.Entries) {
            Console.WriteLine("\tEntry: " + entry.Message);
        }
        EventLog.Delete(log);
    }
}

           
       








Related examples in the same category

1.Check Event Source Existance and Create Event Source
2.Write Message to system event logWrite Message to system event log
3.Get first 5 message from system event log
4.Specify EventLogEntryType
5.Removes the registration for an event source if it has been registered