Monitoring Event log of a remote machine

Posted on 2006-05-04
Last Modified: 2012-08-13
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

Question by:gbzhhu
    LVL 12

    Expert Comment


    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:
    LVL 12

    Author Comment


    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

    LVL 12

    Author Comment


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

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

    LVL 12

    Accepted Solution

    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.;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)..
    LVL 12

    Author Comment


    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


    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    This video discusses moving either the default database or any database to a new volume.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now