Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FileInfo and FileStream length not being updated

Status
Not open for further replies.

JasonDBurke

Programmer
Jun 20, 2001
54
US
Hi,
I am building a windows service. I have spawned off a thread that checks a snort intrusion detection log file size to see if its filesize has changed. Snort.exe has control over this file because it needs to write to it whenever a new alert is triggered. The problem I am having is that in both the FileStream and FileInfo length function, they just keep repeating the same file size over and over again even though the snort alert log is growing. When I stop Snort.exe then the filesize responds with the correct number. How can I retrieve the correct filesize as Snort is running...this seems to be a file control issue. I have been able to do this successfully in other languages such as C/C++ and Pascal.

Thanks,
Jason
 
If you use a StreamWriter , did you set AutoFlush to true ?
If you use a FileStream , do you call Flush() ?

-obislavu-
 
Have you looked at the FileSystemWatcher class? It can raise events when a file or directory gets updated. That way you don't have to sit on the file, waiting for it to be updated.

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Hi,
Yes, Chiph is right but you can try FileSystemWatcher depending on your design and platform.
The specs for FileSystemWatcher class say:

FileSystemWatcher only works on Windows 2000 and Windows NT 4.0. Remote computers must have one of these platforms installed for the component to function properly. However, you cannot watch a remote Windows NT 4.0 computer from a Windows NT 4.0 computer.

Two solutions that I found and are working is to use API:
Keep only the file you want to watch in a directory and use the following API to capture the changes (directory and file)
1.
FindFirstChangeNotification();
FindNextChangeNotification();
FindCloseChangeNotification();
2. CreateFile(); FILE_NOTIFY_INFORMATION structure;
ReadDirectoryChangesW();

-obislavu-



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top