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 migh
A friend of mine uses this method (BackwardReader can be found here):
public static IList GetLogTail(string logname, string numrows)
{
int lineCnt = 1;
List lines = new List();
int maxLines;
if (!int.TryParse(numrows, out maxLines))
{
maxLines = 100;
}
string logFile = HttpContext.Current.Server.MapPath("~/" + logname);
BackwardReader br = new BackwardReader(logFile);
while (!br.SOF)
{
string line = br.Readline();
lines.Add(line + System.Environment.NewLine);
if (lineCnt == maxLines) break;
lineCnt++;
}
lines.Reverse();
return lines;
}