0

I have developed an asp.net c# webpage to allow user to download or view server logs. Once the server and log date is selected they have the option to either open it via Notepad++, or view part of the log in a textbox. Part of the requirement is to show only the last 50 lines of the log in the textbox, this in the only part I'm not sure of can anyone point me in the right direction?

Just now I'm building up the path then setting the text property of the textbox as follows:

                    _PathFrom = @"\\" + ddlServer.SelectedItem.Value + @"\Logs\" + AppOrSession.SelectedItem.Value + @"\" + ddlKernel.SelectedItem.Value + @"\" + txtLogName.Text;
                WebClient MyClient = new WebClient();
                _Log = MyClient.DownloadString(_PathFrom);
                txtLog.Text = _Log;

thanks

DarkW1nter
  • 2,933
  • 11
  • 67
  • 120

1 Answers1

-1
using this method pick last 50 lines from file and display to front end    

public static IList<string> GetLog(string logname, string numrows)
    {
        int lineCnt = 1;
        List<string> lines = new List<string>();
        int maxLines;

        if (!int.TryParse(numrows, out maxLines))
        {
            maxLines = 50;
        }

        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;
    }
Pramod
  • 96
  • 7