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()