EventLog.Delete : EventLog « System.Diagnostics « C# / C Sharp by API






EventLog.Delete

  




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.new EventLog()
2.EventLog.CreateEventSource
3.EventLog.DeleteEventSource
4.EventLog.Entries
5.EventLog.Log
6.EventLog.Source
7.EventLog.SourceExists
8.EventLog.WriteEntry