title: How to monitor a text file and parse new lines?
body: <p>I wondering if there is a way to monitor a .txt file without locking it and have the newly appended lines parsed in order to be sent to a database.</p>
  <p>I know <code>FileSystemWatcher</code> will monitor the txt file without locking it and notify me if a change has occurred. The problem is that it does not tell the lines of data that has been appended. All of the examples I have looked at exclude the part of displaying newly appended lines or doing any processing of the new data. My program has the following structure:</p>
  <pre><code>static void Main(string[] args)
  {
        
    //string line;
  
    //createWatcher (FileSystemWatcher)
    foreach (string line in getLines(@&quot;C://Documents/log.txt&quot;))
    {
      string teststring = line;         
      string[] parts = line.Split(' ', ',', '-', '&gt;', '[', ']');
      StringBuilder builder = new StringBuilder();
              
      foreach (string h in parts)
      {
        builder.Append(h).Append(&quot; &quot;);
      }
  
      string result = builder.ToString();
      string cleanedString = System.Text.RegularExpressions.Regex.Replace(result, @&quot;\s+&quot;, &quot; &quot;);
      string trimString = cleanedString.Trim();
      trimString = trimString.Remove(trimString.Length - 7);
  
      //Console.WriteLine(trimString);
  
      //Process new lines (parse/split)
      //Connect and send to database
    }
  }
  </code></pre>
  <p>So my objective is to monitor a .txt file without locking it.</p>
  <ol>
  <li>Read this file for existing data, and wait for appended data.</li>
  <li>I then want to parse this data and send it to a database.</li>
  </ol>
  <p>Does anyone know how to best approach this? or have a good tutorial?</p>