C# EventLog. Remove selected EventLogEntry
I want to delete entry in every 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
}
}
I think you should not use foreach because you are going to modify the list (delete entry). For first iteration code will work fine but on second iteration it will throw exception saying that 'collection was modified'. Instead of foreach you can use simple for loop.
精彩评论