String testMax = System.getProperty("sigar.testeventlog.max");
if (testMax != null) {
max = Integer.parseInt(testMax);
}
EventLogRecord record;
EventLog log = new EventLog();
log.open(logname);
if (log.getNumberOfRecords() == 0) {
log.close();
return 0; //else log.getOldestRecord() throws Exception
}
int oldestRecord = log.getOldestRecord();
int numRecords = log.getNumberOfRecords();
traceln("oldest=" + oldestRecord +
", total=" + numRecords +
", max=" + max);
for (int i = oldestRecord; i < oldestRecord + numRecords; i++) {
try {
record = log.read(i);
success++;
if (success > max) {
break;
}
} catch (Win32Exception e) {
fail++;
traceln("Error reading record " + i + ": " +
e.getMessage());
}
}
log.close();
traceln("success=" + success + ", fail=" + fail);
return success;
}