C # EventLog. Delete selected EventLogEntry

I want to delete a record at each iteration. Can I do it? Here is my code

static void Main(string[] args)
{

    el = new EventLog();
    el.Log = "XMLWatcherLog";
    el.Source = "XMLWatcherSource";


    string netStr =string.Empty;

    foreach (EventLogEntry entry in el.Entries)
    {
        netStr += "<item>" + "<path>" + entry.Message + "</path>";

       // here i want to delete entry
    }

}
+3
source share
1 answer

I think you should not use foreach, because you are going to change the list (delete the entry). It will work fine for the first iteration code, but it will throw an exception in the second iteration, saying that "the collection has been changed." Instead of foreach, you can use a simple loop.

+1
source

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


All Articles