GetNumberOfEventLogRecords返回不正确的事件日志数 [英] GetNumberOfEventLogRecords returns incorrect number of event logs

查看:792
本文介绍了GetNumberOfEventLogRecords返回不正确的事件日志数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个C ++代码读取事件日志记录

I have this C++ code to read the event log records

DWORD GetLogRecords(LPCWSTR wsLogFile)
{
  HANDLE hEvt = OpenEventLog(NULL, wsLogFile);
  if (hEvt==NULL) return 0;

  DWORD dwTotalRecords;
  BOOL res = GetNumberOfEventLogRecords(hEvt, &dwTotalRecords);
  CloseEventLog(hEvt);

  return (res != 0) ? dwTotalRecords : 0;
}

结果

atlTraceGeneral - C:\Windows\system32\winevt\logs\ACEEventLog.evtx - 23499 Total Records
atlTraceGeneral - C:\Windows\system32\winevt\logs\Application.evtx - 23499 Total Records
atlTraceGeneral - C:\Windows\system32\winevt\logs\ConnectionInfo.evtx - 23499 Total Records
atlTraceGeneral - C:\Windows\system32\winevt\logs\Error.evtx - 23499 Total Records
atlTraceGeneral - C:\Windows\system32\winevt\logs\HardwareEvents.evtx - 23499 Total Records
atlTraceGeneral - C:\Windows\system32\winevt\logs\Internet Explorer.evtx - 23499 Total Records
atlTraceGeneral - C:\Windows\system32\winevt\logs\Key Management Service.evtx - 23499 Total Records
 ...

此功能与我的计算机上的所有.EVTX日志文件的完整路径(150个日志文件)。并且每次返回23499!我的日志文件有不​​同的大小和一些0,为什么我总是得到23499?

I have called this function with the full path of all the .EVTX log files on my computer (150 log files). And each time it returns 23499 ! My log files have different sizes and some 0, why I always get 23499 ?

UPDATE2:在我清除应用程序日志现在我获得0的所有.evtx日志文件。我认为它总是获取应用程序日志而不是指定的.evtx文件。

UPDATE2: After I have cleared the Application logs now I get 0 for all the .evtx log files. I think it always gets the application log instead of the specified .evtx file.

更新:正如Remy Lebeau建议的,但仍然是相同的结果。

UPDATE: As Remy Lebeau suggested, but still the same result.

推荐答案

为了其他人的利益,这个问题的解决方案是 OpenEventLog 路径名。而是必须给它事件日志的源名称(类似HardwareEvents)。

For the benefit of others, the solution to this problem is that OpenEventLog doesn't accept a pathname. Instead you have to give it the source name of the event log (something like "HardwareEvents").

如果调用具有无效源名称(包括提供路径名)的 OpenEventLog ,那么如文档所述,它将打开 log:

If you call OpenEventLog with an invalid source name (which includes providing a pathname), then as documented it will open the Application log instead:


如果指定自定义日志并且找不到, b服务打开应用程序日志。

If you specify a custom log and it cannot be found, the event logging service opens the Application log.

这篇关于GetNumberOfEventLogRecords返回不正确的事件日志数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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