By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,086 Members | 1,875 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,086 IT Pros & Developers. It's quick & easy.

How to dynamically display entries made into a growing log file

P: n/a
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

Sep 29 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Hello BS,

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

1Use a timer and display the contents every second (or so).
2Use 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.
3Use 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

Sep 29 '06 #2

P: n/a
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:

1Use a timer and display the contents every second (or so).
2Use 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.
3Use 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
Sep 29 '06 #3

P: n/a
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/mk...ntswatcher.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:

1Use a timer and display the contents every second (or so).
2Use 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.
3Use 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
>
>

Sep 30 '06 #4

P: n/a
Hi Brian.
Thanks a lot for your help!!! I used a combination of the timer and the
FileSystemWacher technique to implement my solution. Thanks a lot once
agian. The example helped mee too!..and my apologies for not being able
to explain my second question properly.

Thanks and have a great day!
Suman

brians wrote:
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/mk...ntswatcher.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:
>
1Use a timer and display the contents every second (or so).
2Use 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.
3Use 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
Oct 4 '06 #5

P: n/a
Hi Brian.
Thanks a lot for your help!!! I used a combination of the timer and the
FileSystemWacher technique to implement my solution. Thanks a lot once
agian. The example helped mee too!..and my apologies for not being able
to explain my second question properly.

Thanks and have a great day!
Suman

brians wrote:
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/mk...ntswatcher.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:
>
1Use a timer and display the contents every second (or so).
2Use 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.
3Use 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
Oct 4 '06 #6

P: n/a
Hi Brian.
Thanks a lot for your help!!! I used a combination of the timer and the
FileSystemWacher technique to implement my solution. Thanks a lot once
agian. The example helped mee too!..and my apologies for not being able
to explain my second question properly.

Thanks and have a great day!
Suman

brians wrote:
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/mk...ntswatcher.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:
>
1Use a timer and display the contents every second (or so).
2Use 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.
3Use 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
Oct 4 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.