Log Viewer

Feb 23, 2007 at 6:30 PM
Mar 8, 2007 at 6:49 AM
Edited Mar 8, 2007 at 6:50 AM
Hi Scot,

I have download and installed LogView on my WSS box. This feature is really good and a much needed utility. After playing with the feature I found that it had difficulty opening the latest logfile as it was raising IOException with a message that started like this - ""The process cannot access the file"

After looking at your code I made the following modifications to the FillGrid function -

    protected void FillGrid(object sender, EventArgs e)
            // Your datatable and initialization stuff is unchanged            
            //Fill table
            // Used FileStream to open the file in ReadWrite share in order to avoid IOException.
	    FileStream logFile = new FileStream(listFiles.SelectedValue, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            // Passed FileStream to streamreader
            StreamReader reader = new StreamReader(logFile);
            // Your code is unchanged in this part (looping stuff)
            // Just before catch I added dispose

Kind Regards,
Mar 9, 2007 at 1:30 AM
Excellent! Thank you. I will update the next release with this change.
Mar 9, 2007 at 5:37 AM
Edited Mar 9, 2007 at 5:38 AM
Hi Scot,

You welcome.... I have made another two changes to your code.

The first change is in the Page_Load function. The change involves using the SPWebService object to get a reference to the Farm. This eliminates the need for the connection string.

      //Open the farm
      //SPFarm farm = SPFarm.Open("Data Source=server.domain.com;Initial Catalog=WSSS;Integrated Security=SSPI");
      SPFarm farm = SPWebService.ContentService.Farm;

The second change is a change to FillGrid. I now load the file into StringCollection so that I can display the log file backwards (newest on top).

            reader.ReadLine().Split(new char[] { '\t' });
            StringCollection lines = new StringCollection();
            // Read the log file
            while (!reader.EndOfStream)

Kind Regards,
Mar 21, 2007 at 1:50 AM
Release 2.0 is now posted with support for opening the current active log and sorting with newest on top.