1

I am trying to get printer-related logs using EventLog.

I've enumerated all logs in system, using hint from this question, like that:

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

And I got log name of needed log - Microsoft-Windows-PrintService/Operational.

However, this piece of code is crashing:

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

with

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.

I am running MSVC 2015 under administrator.

new EventLog("Application");

is working like a charm, how I can create custom nested event log?

1 Answer 1

1

If you're only looking to read events you can try the EventReader class:

 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());
 }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.