Here is the method that takes event file and ID as parameters, it returns EventRecord
public static EventRecord GetEventRecord(string eventFile, int eventID)
{
var xpathQuery = string.Format("*[System/EventID={0}]", eventID);
var query = new EventLogQuery(eventFile, PathType.FilePath, xpathQuery);
var reader = new EventLogReader(query);
return reader.ReadEvent();
}
usage example :
static void Main(string[] args)
{
var rec = GetEventRecord(@"w:\kanta\eventi.evtx", 903);
/// due to a bug you have to set current culture to en-US or FormatDescription won't work
/// https://connect.microsoft.com/VisualStudio/feedback/details/498054/net-3-5-sp1-eventrecord-formatdescription#
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Console.Write(rec.FormatDescription());
Console.ReadKey();
}