How to remove all events from the application event log for only one source?

I use the application event log to write messages about the activities taking place in my program. I set the source to the name of my application. I would like to offer the user the ability to clear only events related to my program. Is it possible? I see only a way to clear the entire log.

I am using C # in .NET 2.0.

+3
source share
2 answers

Unable to delete specific events from the event log. It clears all events or nothing.

+1
source

This is part of the code from the MSDN library if that is what you are looking for.

  string logName;

    if (EventLog.SourceExists("MySource"))
    {
        // Find the log associated with this source.    
        logName = EventLog.LogNameFromSourceName("MySource", ".");
        // Make sure the source is in the log we believe it to be in. 
        if (logName != "MyLog")
            return;
        // Delete the source and the log.
        EventLog.DeleteEventSource("MySource");
        EventLog.Delete(logName);

        Console.WriteLine(logName + " deleted.");
    }
    else
    {
        // Create the event source to make next try successful.
        EventLog.CreateEventSource("MySource", "MyLog");
    }

 if (!EventLog.SourceExists(source))
        {
            EventLog.CreateEventSource(source, additional);
        }

,

 EventLog.WriteEntry(Source, error, EventLogEntryType.Error);

, ,

 EventLog myEventLog = new EventLog(Constants.EventSource);
 myEventLog.Clear();

, . , :)

+1

Source: https://habr.com/ru/post/1734073/


All Articles