Follow me on Twitter at Twitter.com/wbm
FYI, I'm blogging most of my stuff over at More Wally now.
You might want to add my rss feed to your reader at:http://morewally.com/cs/blogs/wallym/rss.aspx
Using the Log Parser in an ASP.NET Web Application - Wallace B. McClure

Wallace B. McClure

All About Wally McClure - The musings of Wallym on Web, HTML5, Mobile, MonoTouch for iPhone, MonoDroid for Android, and Windows Azure.

News

Personal Blog

Work Blog

.NET

Book Authors

Business

Family

Friends

Georgia Tech Bloggers

Personal

Archives

Using the Log Parser in an ASP.NET Web Application

I needed to query some IIS log files last week.  I wanted to break down some records into the request over a 24 hour period.  I wrote the code below.  The two special issues that I had to work through are separating out the hours through the Quantize command and then translating the resulting LogQueryRecordSet into a DataTable.  If you have any suggestions, please send them to me.

Wally

        Dim strDateStart As String = Me.calDateStart.SelectedDate.ToString("yyyy-MM-dd")
        Dim strDateEnd As String = Me.calDateEnd.SelectedDate.ToString("yyyy-MM-dd")
        Dim strSql As String = "select QUANTIZE( time, 3600 ) as qtTime, count(qtTime) as TimeCount from c:\logfil~1\ex*.log where date >= '" & strDateStart & "' and date < '" & strDateEnd & "' group by qtTime"
        Dim objMsUtil As New MSUtil.LogQueryClass
        Dim objRS As MSUtil.ILogRecordset
        Dim objRow As MSUtil.ILogRecord
        Dim dtData As New DataTable
        Dim dcData As DataColumn
        Dim drData As DataRow
        objRS = objMsUtil.Execute(strSql)
        dcData = New DataColumn("Time", System.Type.GetType("System.String"))
        dtData.Columns.Add(dcData)
        dcData = New DataColumn("DownLoadCount", System.Type.GetType("System.Int32"))
        dtData.Columns.Add(dcData)

        While Not (objRS.atEnd)
            drData = dtData.NewRow()
            objRow = objRS.getRecord()
            drData("Time") = Convert.ToDateTime(objRow.getValue("qtTime")).ToShortTimeString
            drData("DownLoadCount") = objRow.getValue("TimeCount")
            dtData.Rows.Add(drData)
            objRS.moveNext()
        End While

        Me.dgSearchResults.DataSource = dtData
        Me.dgSearchResults.DataBind()

Comments

bunbun said:

I know this post is quite old but I stumbled upon it as I was searching for info on the log parser. I'm sure you've moved on but I took what you did and tried to make it more generic. Basically I created a couple of functions that would take the recordset object returned from a query and convert it to a datatable so it can easily be used with a gridview or other databound control. In any event, I found your post to very helpful as it got me going in the right direction.....

   Protected Function ConvertILogRecordsetToDataTable(ByRef objRS As MSUtil.ILogRecordset) As DataTable

       Dim i As Integer

       Dim dtTemp As New DataTable

       Dim dr As DataRow

       Dim objRow As MSUtil.ILogRecord

       'Create table columns

       For i = 0 To objRS.getColumnCount - 1

           dtTemp.Columns.Add(objRS.getColumnName(i), GetDotNetType(objRS.getColumnType(i)))

       Next

       'Populate table

       While Not (objRS.atEnd)

           dr = dtTemp.NewRow()

           objRow = objRS.getRecord()

           For i = 0 To dtTemp.Columns.Count - 1

               dr(i) = objRow.getValue(i)

           Next

           dtTemp.Rows.Add(dr)

           objRS.moveNext()

       End While

       ConvertILogRecordsetToDataTable = dtTemp

   End Function

   Protected Function GetDotNetType(ByVal iLogType As Integer) As Type

       Select Case iLogType

           Case 0

               GetDotNetType = GetType(Integer)

           Case 1

               GetDotNetType = GetType(DBNull)

           Case 2

               GetDotNetType = GetType(Double)

           Case 3

               GetDotNetType = GetType(String)

           Case 4

               GetDotNetType = GetType(Date)

           Case Else

               GetDotNetType = GetType(String)

       End Select

       GetDotNetType = GetType(String)

   End Function

# August 8, 2008 5:57 PM

Doug said:

Hey, Wally, did you have any issues with permissions?  I've been struggling with this error:

Creating an instance of the COM component with CLSID {8CFEBA94-3FC2-45CA-B9A5-9EDACF704F66} from the IClassFactory failed due to the following error: 80004005

when I try to instantiate the MSUtil.LogQueryClassClass.

# October 28, 2008 6:04 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)