我发现很多关于Log Parser的线程,但没有一个符合我的愿望,
我需要在日志解析器上应用此查询 从安全中选择*
获取事件行,然后逐行读取它们,知道我访问哪个列...
请帮忙......
应该是什么: 1.通过LogParser.dll查询Windows事件(使用MSUtill库) 2.获取并将行放在任何容器内 3.逐行读取行 4.能够分隔行的每个单元格,并像访问事件id列或消息列一样单独读取...
有东西,但我得到了它们, 例如,这个人使用它,采取单行,但我需要多行,我想知道接下来要转换什么:|我需要使用什么类
LogQueryClass logger = new LogQueryClassClass();
COMIISW3CInputContextClass inputContext = new COMIISW3CInputContextClassClass();
string query = // i change it during test
ILogRecord record = logger.Execute(query, inputContext).getRecord();
或另一个使用它:它似乎也返回单个结果
// prepare LogParser Recordset & Record objects
ILogRecordset rsLP = null;
ILogRecord rowLP = null;
LogQueryClassClass LogParser = null;
COMW3CInputContextClassClass W3Clog = null;
double UsedBW = 0;
int Unitsprocessed;
double sizeInBytes;
string strSQL = null;
LogParser = new LogQueryClassClass();
W3Clog = new COMW3CInputContextClassClass();
try
{
//W3C Logparsing SQL. Replace this SQL query with whatever
//you want to retrieve. The example below
//will sum up all the bandwidth
//Usage of a specific folder with name
//"userID". Download Log Parser 2.2
//from Microsoft and see sample queries.
strSQL = //the query (i changed it during test)
// run the query against W3C log
rsLP = LogParser.Execute(strSQL, W3Clog);
rowLP = rsLP.getRecord();
Unitsprocessed = rsLP.inputUnitsProcessed;
if (rowLP.getValue(0).ToString() == "0" ||
rowLP.getValue(0).ToString() == "")
{
//Return 0 if an err occured
UsedBW = 0;
return UsedBW;
}
//Bytes to MB Conversion
double Bytes = Convert.ToDouble(rowLP.getValue(0).ToString());
UsedBW = Bytes / (1024 * 1024);
我发现最好的查询是这个,它在注册内搜索(我没有原始查询,因为我改变了它
ILogRecordset rs = null;
try
{
LogQueryClass qry = new LogQueryClass();
COMRegistryInputContextClass registryFormat = new COMRegistryInputContextClass();
string query = //Chnaged it
rs = qry.Execute(query, registryFormat);
for (; !rs.atEnd(); rs.moveNext())
Console.WriteLine(rs.getRecord().toNativeString(","));
}
finally
{
rs.close();
}
还有一些东西,似乎将数据返回给SQL而不是活动对象:|
让我补充一下,我的查询(使用传递“log parser.exe”参数)是这样的,但是对于我来说,在服务中调用exe文件真是太无礼了。
myProc.StartInfo.Arguments = " \"select * INTO AuditLogParser from \\\\" + Dns.GetHostName() +
"\\security WHERE TimeGenerated >= '" + startDate +
"' and TimeGenerated <'" + endDate +
"' and (eventid=560 or eventid=540)\" -o:SQL -server:\"" +
Dns.GetHostName() +
"\\sqlexpress\" -database:SecurityLog -driver:\"SQL Server\" -username:TrainAudit -password:Password.110 -createtable:OFF";
答案 0 :(得分:5)
以下示例代码使用LogParser从名为C:\Bat
的本地目录中读取文件名和大小
LogQueryClass logQuery = new LogQueryClassClass();
COMFileSystemInputContextClass inputFormat = new COMFileSystemInputContextClassClass();
inputFormat.recurse = 0;
String strQuery = @"SELECT Name, Size FROM 'C:\Bat\*.*' ORDER BY Name ASC";
ILogRecordset results = logQuery.Execute(strQuery, inputFormat);
while (! results.atEnd())
{
Console.WriteLine(String.Format("File: {0} Size: {1}", results.getRecord().getValue("Name"), results.getRecord().getValue(1)));
results.moveNext();
}
请注意,我可以通过查询中列的名称或列索引来访问该列。