Efran is correct to use the FileSystemWatcher class rather than polling, since you have to close the file to allow it to be renamed anyway you may as well mkae use of the watcher.
An example of the tail utility using the FileSystemWatcher class. http://dotnetjunkies.com/WebLog/johnwood/archive/2005/01/05/41694.aspx Graeme Taylor <[EMAIL PROTECTED]> 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 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
