Problem fetching specific log from Event Logs

  • Thread starter Thread starter RohitVaidya
  • Start date Start date
R

RohitVaidya

Guest
I want to read a particular event log under "Applications and Services Logs" category of Event Viewer. I am reading this from a remote computer.

The log which I want to read from Event Viewer is with the name: "BookService" under the above mentioned category.

I tried this code but each time the loop ends because eventDetail is null even when BookService log exists.

string queryString = "*[System/Provider/@Name=\"BookService\"]"; // XPATH Query
SecureString pw = GetPassword();

EventLogSession session = new EventLogSession(
"xx.xx.xxx.xx", // Remote Computer
"RP", // Domain
"user1234", // Username
pw,
SessionAuthentication.Default);

pw.Dispose();

// Query the Application log on the remote computer.
EventLogQuery query = new EventLogQuery("Application", PathType.LogName, queryString);
query.Session = session;

try
{
EventLogReader logReader = new EventLogReader(query);

for (EventRecord eventdetail = logReader.ReadEvent(); eventdetail != null; eventdetail = logReader.ReadEvent())
{
// Read Event details
string logname = eventdetail.LogName;

}

Continue reading...
 
Back
Top