1
votes

Is there any way to fetch 'Application and Services logs' from event viewer by using c#? I could able to read the logs from windows logs but not from application and services logs. Exactly what i require is to read the log named 'Microsoft-Windows-PrintService/Operational'

Please suggest...!

Thanks in Adv.

2

2 Answers

1
votes

Try this:

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
}
0
votes

Use EventLog class with your custom log name. Read at MSDN for more.