Video Screencast Help
Symantec to Separate Into Two Focused, Industry-Leading Technology Companies. Learn more.

Pretty Log Parser

Created: 30 Aug 2012 • Updated: 30 Aug 2012 | 2 comments
Rob.Wilcox's picture
+1 1 Vote
Login to vote

 

Following on from my previous post about LogParser, a few weeks ago I decided to make something 'more pretty'.  Here is what I built:
 
 
To do this I followed these steps:
 
1. Install Log Parser
2. Create a new Web Solution in Visual Studio 2010..
3. Add a reference to LogParser.dll
4. Add 'using MSUtil;' at the top of the C# code
 
Then you can do cool things like:
 
             // Get Todays date, and form the filename
            string filename = "" ;
            filename = "ex" + String .Format( "{0:yyMMdd}", DateTime .Now) + ".log" ;
 
            // prepare LogParser Recordset & Record objects
            ILogRecordset rsLP = null ;
            ILogRecord rowLP = null ;
 
            LogQueryClass LogParser = null ;
            COMW3CInputContextClass W3Clog = null ;
 
            string strSQL = null ;
 
            LogParser = new LogQueryClass ();
            W3Clog = new COMW3CInputContextClass ();
 
            strSQL = "select TO_DATE(QUANTIZE(TO_LOCALTIME(TO_TIMESTAMP(date, time)), 86400)) AS Day, ";
            strSQL = strSQL + "   count(*) as Hits " ;
            strSQL = strSQL + " from " ;
            strSQL = strSQL + " c:\\WINDOWS\\system32\\LogFiles\\W3SVC1\\" + filename + " " ;
            strSQL = strSQL + " where " ;
            strSQL = strSQL + " cs-uri-stem like '%search%.asp' " ;
            strSQL = strSQL + " and " ;
            strSQL = strSQL + " sc-status = 200 " ;
            strSQL = strSQL + " group by Day " ;
 
            int count = 0;
            try
            {
                rsLP = LogParser.Execute(strSQL, W3Clog);
                while (!rsLP.atEnd())
                {
                    rowLP = rsLP.getRecord();
 
                    count++;
                    lblNumSearches.Text = rowLP.getValue(1).ToString();
                    rsLP.moveNext();
                }
            }
            catch
            {
            }
            if (count == 0) // there was no data
                lblNumSearches.Text = "0 so far" ;
 
The rest of the code, well, the whole solution is provided in the download link below.
 
 
To get it working (this was on Windows 2003)
 
Create a new Virtual Directory ready to deploy the code to.  You need the stuff in the first zip file (the second is the source code)
 
Edit the Virtual Directory and change it to  be an 'application'.  I let mine run under the Default App Pool
 
You then need to give the account that the default app pool is running under, permissions to the W3SVC log folder.
 
So for me that is this account:
 
 
Give the account read-only access, and hey presto, it should start to work like this:
 
 
 
 

 

Comments 2 CommentsJump to latest comment

AKL's picture

Thanks for the query Rob

Adding to above, I am not sure if you're already aware about same, there is a tool from Microsoft called "Log Parser Studio" which has various inbuilt Log Parser queries.

Reference: http://blogs.technet.com/b/exchange/archive/2012/03/07/introducing-log-parser-studio.aspx

Hope you find this tool helpful ! :-)

Thank You

AKL

0
Login to vote
Rob.Wilcox's picture

Yeah there are some quite good bits and pieces that creep out of the woodwork with regards to Log Parser. I don't think people realise it's potential.

 

I mean, I definitely don't !!

 

But hopefully this download, and my other blogs/articles that have touched on Log Parser will hopefully give people the idea to 'give it a whirl and see what it can do'.

0
Login to vote