2016-09-30 20 views
1

EventLogを使用してプリンタ関連のログを取得しようとしています。C#のネストされたイベントログにアクセス

foreach (var e in EventLogSession.GlobalSession.GetLogNames()) { 
      Console.WriteLine(e); 
     } 

を私は必要なログの名前ログインしました - Microsoft-Windows-PrintService/Operationalを:

私はそのように、this questionからヒントを使用して、システム内のすべてのログを列挙しました。

しかし、コードのこの作品は、クラッシュさ:

An unhandled exception of type 'System.InvalidOperationException' occurred in System.dll 
Additional information: The event log 'Microsoft-Windows-PrintService/Operational' on computer '.' does not exist. 

var evt = new EventLog("Microsoft-Windows-PrintService/Operational"); 

を私は管理者の下でMSVC 2015を実行しています。

new EventLog("Application"); 

は、魅力的な働きをしています。どのようにカスタムネストされたイベントログを作成できますか?

答えて

1

あなただけのイベントを読み取るために探している場合は、EventReaderクラスを試すことができます。

var printerServiceQuery = new EventLogQuery("Microsoft-Windows-PrintService/Operational", PathType.LogName); 
var reader = new EventLogReader(printerServiceQuery); 
EventRecord entry = null; 
while((entry = reader.ReadEvent()) != null) 
{ 
    Console.WriteLine(entry.FormatDescription()); 
} 
関連する問題