Last line of file

  • Thread starter Thread starter Pablo Tola
  • Start date Start date
P

Pablo Tola

How can obtain the last line in a log file?

regards,

(e-mail address removed)
 
Sorry for the C# code if you like vb.

private static string GetLastLine( string filename )
{
System.IO.StreamReader reader = null;

try
{
new StreamReader( filename );

reader.BaseStream.Position = reader.BaseStream.Length - 1;

while ( ( char ) reader.BaseStream.ReadByte() != '\n' )
reader.BaseStream.Position -= 2;

return reader.ReadLine();

}
finally
{
reader.Close();
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top