title: How to read last "n" lines of log file
body: <p>need a snippet of code which would read out last "n lines" of a log file. I came up with the following code from the net.I am kinda new to C sharp. Since the log file might be 
  quite large, I want to avoid overhead of reading the entire file.Can someone suggest any performance enhancement. I <strong>do not really want to read each character</strong> and change position.</p>
  
  <pre><code>   var reader = new StreamReader(filePath, Encoding.ASCII);
              reader.BaseStream.Seek(0, SeekOrigin.End);
              var count = 0;
              while (count &lt;= tailCount)
              {
                  if (reader.BaseStream.Position &lt;= 0) break;
                  reader.BaseStream.Position--;
                  int c = reader.Read();
                  if (reader.BaseStream.Position &lt;= 0) break;
                  reader.BaseStream.Position--;
                  if (c == '\n')
                  {
                      ++count;
                  }
              }
  
              var str = reader.ReadToEnd();
  </code></pre>