Re: How to dynamically display entries made into a growing log fil

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Suman,

I'm not sure I understand your application design nor your use of the terms
"compile time" and "run time". Generally speaking, infinite loops and event
driven UI don't go well together.

The way I would monitor a file and display its contents is to use the
FileSystemWatcher object and in the changed event, update the display to
reflect the new contents. If you're in an infinite loop, your application
would never have a chance to update the display with the new contents of the
file.

In any event, you might want to look up on the Code Project at the following
link. The project sounds like just the ticket you're looking for:

http://www.codeproject.com/csharp/mkfilecontentswatcher.asp
--
brians
http://www.limbertech.com


"Aspiring .NET Programmer" wrote:

Hi Brains

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?

I havent explored the timer option yet. Any sample code that I may look
at?

Will be glad to provide any other info.

Thanks a lot for your time!
Suman

brians wrote:
Hello BS,

To display the contents of the log file you could do a couple of different
things:

1> Use a timer and display the contents every second (or so).
2> Use a FileSystemWatcher - it is designed to listen to the file system
change notifications and raise events when a directory, or file in a
directory, changes.
3> Use some other interprocess synchronization primative - probably overkill
for what you want to do.
--
brians
http://www.limbertech.com


"Aspiring .NET Programmer" wrote:

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




.



Relevant Pages

  • Re: How to dynamically display entries made into a growing log file
    ... does pick up events that may happen at compile time. ... To display the contents of the log file you could do a couple of different ... I want to create a windows form application, which, upon ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: How to dynamically display entries made into a growing log fil
    ... FileSystemWatcher object and in the changed event, update the display to ... I did discover the 'filesystemwatcher' class earlier. ... To display the contents of the log file you could do a couple of different ... I want to create a windows form application, which, upon ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: How to dynamically display entries made into a growing log fil
    ... FileSystemWatcher object and in the changed event, update the display to ... I did discover the 'filesystemwatcher' class earlier. ... To display the contents of the log file you could do a couple of different ... I want to create a windows form application, which, upon ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: How to dynamically display entries made into a growing log fil
    ... FileSystemWatcher object and in the changed event, update the display to ... I did discover the 'filesystemwatcher' class earlier. ... To display the contents of the log file you could do a couple of different ... I want to create a windows form application, which, upon ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: How to dynamically display entries made into a growing log file
    ... The 'filesystemwatcher' windows control does exactly this. ... you create a Windows Form in VS 2005 and call up your SERVER EXPLORER. ... I have a windows service which writes into a log file periodically ...
    (microsoft.public.dotnet.general)