I went through all relevant topics, but I didn't find an answer. I'm running a WMI query to retrieve the datetime of the oldest event in the Application Log. Unfortunately the query below always return 0 values, but apparently syntax is correct, because no error message is returned. Any idea why this happens? Actually c# embedded solution downloads the whole Eventviewer and since I'm connecting to remote machines, performances are horrible. Therefore I chose WMI query
SelectQuery query = new SelectQuery("select * from Win32_NtLogEvent where Logfile ='" + logFileName + "' and RecordNumber = '1'");
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query, opt)) {
foreach (ManagementObject mo in searcher.Get()) {
DateTime firstEventTime;
DateTime.TryParseExact(mo["TimeGenerated"].ToString().Substring(0, 12), "yyyyMMddHHmm", null, DateTimeStyles.None, out firstEventTime);
// if the time of the first entry of the application log is older that the dayback to check date
// set dayback to check to first app log entry date
logbox.writetoLogFile(this.GetType().Name, "First event time is " + firstEventTime, LogLevel.Debug);
if (firstEventTime > endDate) {
endDate = firstEventTime;
logbox.writetoLogTextbox("First eventviewer entry has date " + firstEventTime + ". Check log will stop at this date", Color.Black);
logbox.writetoLogFile(this.GetType().Name, "First eventviewer entry has date " + firstEventTime + ". Check log will stop at this date", LogLevel.Info);
}
}
}
Unfortunately I figured it out now. Record number get not reset, therefore the event 1 has disappeared since ages. :( Any idea how I could gather this info ?
Thanks, Marco
RecordNumber
is a unique identifier and not necessarily match with the LogFile are you using, is something like a primary key, and you get different numbers for each computer, msdn definition forRecordNumber
:So what you should do is get all events with specific LogFile, sort by TimeGenerated and get the older event and make another search for the number of the older event: i.e: