How to Query for an event log details with a given event id?

后端 未结 2 1641
梦谈多话
梦谈多话 2020-11-30 08:07
  1. How to know whether a particular event (given event ID, time and node as inputs) is logged or not? [In this case, I know only one event will be logged]
  2. If the
2条回答
  •  一向
    一向 (楼主)
    2020-11-30 08:44

    You could query the event log in question:

    var sourceName = "MySource";
    var el = new EventLog("Application");
    var latestEntryTime = (from entry in el.Entries.Cast()
                           where entry.Source == sourceName
                           && // put other where clauses here...
                           orderby entry.TimeWritten descending
                           select entry).First();
    

    However, be warned that this approach is slow, since the Entries collection tends to be quite big.

提交回复
热议问题