I am monitoring a folder for changes using java.nio.file.WatchService to see when a file is modified. What I also need is, when I get an ENTRY_MODIFIED event, to see who modified the file. For this I am trying to search the Windows Event Log. So when I receive an event from the WatchService, I traverse the entries in the Windows Event Log using Advapi32Util.EventLogIterator.
Advapi32Util.EventLogIterator iter = new Advapi32Util.EventLogIterator("Security");
while(iter.hasNext()) {
Advapi32Util.EventLogRecord record = iter.next();
}
From this record I retrieve the information I need. My problem is that if I traverse the Event Log exactly at the time when I receive the event from the WatchService, the log record still does not exist there. If I pause for 500 milliseconds and traverse after that, then it works. So it takes some time for the log entry to get written into the Event Log. Is there a way to subscribe to the Event Log so that I receive a notification when it is already updated and ready for traversal, so that I don't wait more than needed? (sometimes 500 milliseconds might be more than necessary, I want to perform the operation as fast as possible)