开发者

C# EventLog. Remove selected EventLogEntry

开发者_JAVA技巧

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜