Graeme,
Please consider you should open a file only when the event handler is
called. So, your open and gather logic would be executed, if the change
frequency is less than 10 changes per second, less times than the
original code sample. Obviously there is some overhead in
opening/closing your files: you should choose the trade off between
having your files "locked" or having them always available (for
renaming) but with a small overhead; personally, in most scenarios I
would go with the latter.
Efran Cobisi
http://www.cobisi.com
Graeme Taylor wrote:
Hi Efran
I had considered using the method you suggest. However, I am only
interested in the tail (i.e. the new lines written) each time the file is
written to.
My thinking was that opening the whole file each time would be more of an
overhead than maintaining the file handle throught the life of the
application / file.
I know I can keep in my object state the number of lines at the last read
using your method and get the tail this way. Is this that the best
approach?
Thanks for tip,
Graeme
On Tue, 17 Apr 2007 12:08:32 +0200, Efran Cobisi <[EMAIL PROTECTED]>
wrote:
Hello Graeme,
The example you have posted the link to is not the better way to execute
a task whenever a file changes: polling for file changes every 100ms and
keeping the file handle open is definitely not the way to go. Instead, I
suggest you to take a look at the FileSystemWatcher class [1]; you could
use it to capture, among others, file/directory change and rename
events, avoiding to place file system locks which could prevent, for
example, file renaming. You could then code your data gathering logic
inside the event handlers attached to the aforementioned events.
[1]
http://msdn2.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx
HTH
Efran Cobisi
http://www.cobisi.com
Graeme Taylor wrote:
Hi,
I am writing an application that will watch log files for certain text
patterns appearing (e.g. errors / warnings). So far, I have created an
application that picks up new lines and will check them using RegEx (based
on CodeProject article http://www.codeproject.com/cs/files/tail.asp).
However, most applications that create the logs will try to rename the
log file when it reaches a certain size, at the moment, my Log Watching
application is preventing this rename taking place.
Would be grateful for any tips on how to get round this.
Thanks in advance for any assistance,
Graeme
___________________________________________________________
Yahoo! Mail is the world's favourite email. Don't settle for less, sign
up for
your free account today
http://uk.rd.yahoo.com/evt=44106/*http://uk.docs.yahoo.com/mail/winter07.ht
ml
===================================
This list is hosted by DevelopMentor? http://www.develop.com
View archives and manage your subscription(s) at
http://discuss.develop.com
===================================
This list is hosted by DevelopMentorĀ® http://www.develop.com
View archives and manage your subscription(s) at
http://discuss.develop.com
===================================
This list is hosted by DevelopMentorĀ® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com
===================================
This list is hosted by DevelopMentorĀ® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com