I am stating to write a little PC tool to read log files using c# or java. The log files will be in .txt format. An application is running and writing logs, and I want my tool to open the log at the same time and refresh automatically when a new line is written to the log file.
My challenge is, how do I detect the log file changes so that my tool will have real-time displaying ability? This is a general question but pseudo codes will be greatly appreciated!
You can use the FileSystemWatcher
class (MSDN page). Be careful though, if you try to open the file while the other process is writing the file you will probably be denied access.
There's a bunch of this questions here, and answers too:
Reading file content changes in .NET
Your target is FileStream object, I suppose.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With