• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1251
  • Last Modified:

Monitoring Event log of a remote machine

I have code that monitors Event log on my PC and when an event is written I get notified, this code was from CodeProject, can't remember the exact url

Does anyone know if it is possible to monitor events from a remote machine?  and if so code example/url

Thanks
0
gbzhhu
Asked:
gbzhhu
  • 3
  • 2
1 Solution
 
sumixCommented:

EventLog class (System.Diagnostics) has MachineName property that allows you to monitor the remote machine event log if you have the necessary rights. For example:

EventLog lg = new EventLog();
lg.Log = "System";
lg.MachineName = "COMPUTER";
lg.EntryWritten +=new EntryWrittenEventHandler(lg_EntryWritten);
lg.EnableRaisingEvents = true;

private void lg_EntryWritten(object sender, EntryWrittenEventArgs e)
{
      Console.WriteLine("new entry");
}

A more complete sample:
http://www.thecodeproject.com/csharp/RTEventReader.asp
0
 
gbzhhuAuthor Commented:
sumix

the code I had was from the same URL and worked OK on my PC.  Perhaps I was just missing the MachineName property setting.  I will give it a shot tomorrow when I get to work

If that works fine, my next task is to listen for multiple machines.  If you have ideas about this please post a comment and if that also works I will have another 500 points ready to dish out

Cheers
0
 
gbzhhuAuthor Commented:


Setting the ComputerName doesn't work.  It results on this error

 Cannot monitor Event log. The log may exist on a remote computer

0
 
sumixCommented:
You're right. You can read event logs on remote computers, but you cannot receive notifications for entries written on remote computers.
There is a small note on the article below, that specify this.
 http://support.microsoft.com/?scid=kb;EN;815314

 I'll let you now if I find another solution (other than using a timer that gets the number of entries and if this is increased, reads the last ones)..
0
 
gbzhhuAuthor Commented:
sumix,

I have to close this question as we both know there is no direct answer but rather some possible workarounds.  You will get grade A for your contribution since there is no better solution than your suggestions.  Thanks for your input, particularly your link to MS site to show that we can't monitor remote server logs, which, to be honest IMNO should be allowed provided you have the correct permissions to the server

Thanks again

Hassan
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now