I'm trying to figure out how to query the PrintService Operational log in vb.net. I'm not trying to write to it but instead read from it in vb.net. Here is what i have so far that works if i just query the "Application" log
Dim logInfo As System.Diagnostics.EventLog = New System.Diagnostics.EventLog()
logInfo.Log = "Application"
logInfo.MachineName = "."
Dim strImage As String = ""
Response.Write("<p>There are " & logInfo.Entries.Count & " entries in the System event log.</p>")
However.. i'm trying to get to the Microsoft.Windows.PrintService.Operational log. Can you not access it or is my syntax wrong. What i tried in was
logInfo.log= "Microsoft.Windows.PrintService.Operational"
and
logInfo.log= "Microsoft-Windows-PrintService/Operational"
both gave me a result of
System.InvalidOperationException HResult=0x80131509 Message=The event log 'Microsoft.Windows.PrintService.Operational' on computer '.' does not exist. Source=App_Web_dxkz1kso StackTrace: at Pages_SampleCode_ConnectToEventLog.Pages_SampleCode_ConnectToEventLog_Load(Object sender, EventArgs e) in C:\Dev\WebAdminV2\Pages\SampleCode\ConnectToEventLog.aspx.vb:line 17
Any ideas? thanks
Jimi - did try.. i think what you are suggesting.. that code looked like this
Dim eventID As String = "307"
Dim logSource As String = "Microsoft-Windows-PrintService/Operational"
Dim sQuery As String = String.Format("*[System/EventID={0}]", eventID)
Dim elQuery = New EventLogQuery(logSource, PathType.LogName, sQuery)
Dim elReader = New System.Diagnostics.Eventing.Reader.EventLogReader(elQuery)
Dim eventList As List(Of EventRecord) = New List(Of EventRecord)()
Dim eventInstance As EventRecord = elReader.ReadEvent()
While eventInstance IsNot Nothing
eventList.Add(eventInstance)
eventInstance = elReader.ReadEvent()
End While
I did not receive any error, however when it did it's while eventInstance IsNot nothing, well it's nothing. I haven't figured out to tell it where i'm pointing it too.. i'm guessing its looking on my local machine.. and there are entries in the log..
Just in case anyone else is interested.. I think i got it to read the log.. many aspects yet to figure out.. but here is what looks like it will read the log.. this is the only code running..just these 3 lines
Dim query As EventLogQuery = New EventLogQuery("Microsoft-Windows-PrintService/Operational", PathType.LogName)
query.ReverseDirection = True
Dim reader As EventLogReader = New EventLogReader(query)
enter code here
User contributions licensed under CC BY-SA 3.0