如何在使用EventLogReader(eventLogQuery)时查找受影响的总行数? [英] How to find total rows affected when using EventLogReader (eventLogQuery)?

查看:416
本文介绍了如何在使用EventLogReader(eventLogQuery)时查找受影响的总行数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用类EventLogReader(eventLogQuery)从服务器读取大约100 000条记录的事件日志。



我正在使用分页每个页面只会在我的屏幕上显示25条记录。因此,我将从第一页的总记录中读取25条记录,在第二页的下一条25条记录中读取等等。



我的问题是如何获取由于在整个100k记录中应用了eventLogQuery,以下片段的总记录数如受影响的总行数?

I'm trying to read eventlogs from a server which has about 100 000 records using class EventLogReader(eventLogQuery).

I'm using pagination and each page will show only 25 records in my screen. So, I will be reading 25 records out of total records for the first page and next 25 records for the second page and so on.

My question is how to get the total records count for the below snippet like total rows affected because of that eventLogQuery applied on the total 100k records?

EventLogReader reader = new 
EventLogReader(eventLogQuery);
                reader.Seek(SeekOrigin.Begin, filter.PageStart);

eventLogs.TotalLogs = **totalRowsAffected**;                    
EventRecord eventInstance = reader.ReadEvent();

int i = filter.PageSize;
while (eventInstance != null && i-- > 0)
{
 try
 {
  eventLogs.Entries.Add(new EventLogData
  {
   Type = eventInstance.LevelDisplayName,
   Source = eventInstance.ProviderName,
   Time = eventInstance.TimeCreated,
   Category = eventInstance.TaskDisplayName,
   EventId = eventInstance.Id,
   User = eventInstance.UserId != null ? eventInstance.UserId.Value : "",
   Computer = eventInstance.MachineName,
   Message = eventInstance.FormatDescription(),
   FullXml = eventInstance.ToXml()
  });
 }catch{}
eventInstance = reader.ReadEvent();
}
}
return eventLogs;




推荐答案

鉴于事件日志是动态的,我不知道你可以不实际枚举记录。当然,一旦你列举它们,它可能会改变,除非你正在查看历史数据。事件阅读器是一个前向阅读流,所以在你完成结果集中有多少之前你不会知道
。我认为你发表的SO帖子基本上是说同样的话。您可以在日志中获取总(当前)事件,但过滤后的子集将需要运行查询,该查询将保留返回记录
直到它用完为止。
Given that the event log is dynamic I don't know that you can without actually enumerating the records. Of course once you enumerate them it has likely changed unless you're looking at historical data. Event reader is a forward reading stream so you won't know until you're done how many were in the resultset. I think the SO post you made is basically saying the same thing. You can get the total (current) events in a log but the filtered subset would require running the query which will keep returning records until it runs out.


这篇关于如何在使用EventLogReader(eventLogQuery)时查找受影响的总行数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆