title: C#: tail like program for text file
body: <p>I have a log file that continually logs short lines. I need to develop a service that reacts (or polls, or listens to) to new lines added to that file, a sort of unix' tail program, so that my service is always up to date reguarding the file.</p>
  
  <p>I don't think that opening a read stream and keeping it opened is a good idea. Maybe I should use the FileSystemWatcher class.</p>
  
  <p>Long story short, I need to parse in real time every new line added to this file.</p>
  
  <p>Any idea help or indication is really appreciated.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>As I've been not very clear. I do not need any program, I am <em>writing</em> a program. For reading (then processing) every new line added to the file. I mean that what I'm looking for is a methodology (or: how to implement this?) for continually <em>tailing</em> a file that keeps on been written.</p>
  
  <p>I have to develop a Windows service that "listens" to this file and does operations on every new line.</p>
  
  <p>So, if in a given moment the file is:</p>
  
  <pre><code>12.31.07 - jdoe [log on] 347
  12.32.08 - ssmith [log on] 479
  12.32.08 - mpeterson [log off] 532
  12.32.09 - apacino [log on] 123
  </code></pre>
  
  <p>in the very moment that the line</p>
  
  <pre><code>12.32.11 - pchorr [log on] 127
  </code></pre>
  
  <p>is added to the log file by the logging program (that I have not access to), I need my Windows service to "react" to the line addiction, intercept the new line (<code>12.32.11 - pchorr [log on] 127</code>) and process it. And so on.</p>
  
  <p>Now, I don't know how to do this. I should poll the file every n seconds, store the last read line in memory and process only the newly added lines. The problem with this is that is very slow, plus I'd be reading a very large file every time.</p>
  
  <p>Or maybe I could use <code>FileSystemWatcher</code>, but I haven't found any example of using it for similar purposes.</p>
  
  <p>So, what would you suggest to get the work done? Thanks.</p>