Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用c#| PrintServices从应用程序和服务日志读取事件日志_C#_Events_Event Viewer - Fatal编程技术网

使用c#| PrintServices从应用程序和服务日志读取事件日志

使用c#| PrintServices从应用程序和服务日志读取事件日志,c#,events,event-viewer,C#,Events,Event Viewer,是否有任何方法可以使用c#从事件查看器获取“应用程序和服务日志”? 我可以从windows日志中读取日志,但不能从应用程序和服务日志中读取。我需要的正是阅读名为“Microsoft Windows PrintService/Operational”的日志 请建议 感谢您在Adv.中使用带有自定义日志名的EventLog类。有关更多信息,请阅读。尝试以下方法: string logType = "Microsoft-Windows-PrintService/Operational"; string

是否有任何方法可以使用c#从事件查看器获取“应用程序和服务日志”? 我可以从windows日志中读取日志,但不能从应用程序和服务日志中读取。我需要的正是阅读名为“Microsoft Windows PrintService/Operational”的日志

请建议


感谢您在Adv.

中使用带有自定义日志名的
EventLog
类。有关更多信息,请阅读。

尝试以下方法:

string logType = "Microsoft-Windows-PrintService/Operational";
string query = "*[System/EventID=307]";

var elQuery = new 
    EventLogQuery(logType, PathType.LogName, query);
var elReader = new EventLogReader(elQuery);

for (EventRecord eventInstance = elReader.ReadEvent(); eventInstance != null; eventInstance = elReader.ReadEvent())
{
    //your code
}