MS Log Parser 2.2查询错误
我试图确定用户是否使用MS Log Parser 2.2从FTP下载文件
尽管我已经使用了多个示例查询,但我仍然无法获取解析器SQL查询。
水下分析器查询不起作用:
strSQL = "SELECT date,COUNT(*) AS downloads,c-ip "
strSQL = strSQL & "FROM C:tempLog*.log "
strSQL = strSQL & "WHERE cs-method='RETR' "
strSQL = strSQL & "GROUP BY date,c-ip "
错误:
RecordSet cannot be used at this time [Unknown Error]
题:
我如何创建查询:
- SELECT Date and Time of download
- Where user = 'xxx'
- WHERE RETR = is a download
- WHERE Filename = u_ex150709.log or xxx
在C#中的答案也是受欢迎的
VB.net代码:
Dim rsLP As ILogRecordset = Nothing
Dim rowLP As ILogRecord = Nothing
Dim LogParser As LogQueryClassClass = Nothing
Dim W3Clog As COMW3CInputContextClassClass = Nothing
Dim UsedBW As Double = 0
Dim Unitsprocessed As Integer
Dim strSQL As String = Nothing
LogParser = New LogQueryClassClass()
W3Clog = New COMW3CInputContextClassClass()
Try
strSQL = "SELECT date,COUNT(*) AS downloads,c-ip "
strSQL = strSQL & "FROM C:tempLog*.log "
strSQL = strSQL & "WHERE cs-method='RETR' "
strSQL = strSQL & "GROUP BY date,c-ip "
'run the query against W3C log
rsLP = LogParser.Execute(strSQL, W3Clog)
'Error occurs in the line below
rowLP = rsLP.getRecord()
就像你我已经编写了利用LogParser的工具,例如http://eventanalyser.appointmentsbook.com/
尽管早在2004年(使用.Net 1.1)我没有下载的好处:https://visuallogparser.codeplex.com/
检查他们的源代码,让你的查询工作(VisualLogParser),然后在你的项目中简单地引用它,并享受开源社区的善良。
至于你关于FTP榨取查询,这里是MSDN文章:http://blogs.msdn.com/b/robert_mcmurray/archive/2010/09/02/detecting-ftp-leeches-with-logparser.aspx
SELECT date,COUNT(*) AS downloads,c-ip,x-session
FROM *.log
WHERE cs-method='RETR'
GROUP BY date,c-ip,x-session
HAVING COUNT(*) > 100
有一件事在你查询时看起来很突出,我创建了一个GUI来动态创建,你在文件路径周围缺少单引号:
strSQL = strSQL & "FROM C:tempLog*.log "
尝试这个:
strSQL = strSQL & "FROM 'C:tempLog*.log' "
(并使用StringBuilder,而不是字符串连接...只是为了养成最佳实践的习惯)
按照:
如果引号不能先解决问题,那么请尝试使用单个日志文件而不是通配符*.log
来缩小语法错误的范围。 LogParser的设计目的不是为了帮助诊断问题查询,而是Gabriele Giuseppini将其设计为快速,快速!