How to dynamically display entries made into a growing log file

S

Suman

Happy Friday everyone!!!

I am working on a windows service and a C# application and needed some
help with certain functionality. Please read through my issue below.
Thanks!

I have a windows service which writes into a log file periodically
(text file). I want to create a windows form application, which, upon
invocation should continuously display the contents of the log file.
Even the newly made entries into the log file while the windows form
application has started running should be displayed dynamically at run
time.

Is that possible? and how should I go about it.

If such continuous monitoring of a log file cannot be implemented as a
windows form app, then how else could that be implemented?

The main idea is to continuously display to the user the entries that
are being made to the log file by the windows service.

I would be more than happy to provide any further information.

Thanks a lot for any help!!!
BS
 
G

Guest

Hi Suman,

The 'filesystemwatcher' windows control does exactly this. You point this
windows control to a file and it will fire events whenever the file changes
(i.e. modifications etc.). You can then re-read the file (or do whatever) to
refresh your display of information. Yes - windows forms is a good mechanism
to accomplish this.

In fact Microsoft has even anticipated applications needing to do this. If
you create a Windows Form in VS 2005 and call up your SERVER EXPLORER. Click
on your machine (machine name in server explorer) and you will see a tree
node that points to the EVENT LOGS. Just drag an event log over to your form
and drop it on your form. VS 2005 will automatically create a
'filesystemwatcher' control on your form pointing directly to the event log
you just dragged. Works very nicely and 'bingo' you have a
'filesystemwatcher' set up exactly to do what you want to do.
 
S

Suman

Hi Franklin,

Thanks a lot for that information!
Yes. I did discover the 'filesystemwatcher' class earlier. And was
working on that while I posted my query.

My problem while using that is that the following statement:

watcher.Changed += new FileSystemEventHandler(OnChanged);

does pick up events that may happen at compile time. That is if I have
a break point on the above line and put the statement in a finite loop
and start compiling, stop at one of the break point and go change the
log file i am pointing to and then coninue the next iteration of the
loop, it does identify the modification and calls the delegated method.


However, the appropriate output is only displayed once the compilation
has finished. Now, I need an application that continuosly monitors the
logfile and as and when it identifies any modification in it, displays
the log files contents on the windows form.

Basically need to "file changed" event captured at runtime and not
compile time. If I put the above loop in an infinite loop, obviously
the compilation never ends and I just see a blank form. :(

Am I missing something here?

Will be glad to provide any other info.

Thanks a lot for your time!
Suman
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top