locked
EventLogWatcher not supported on Windows 2003 platform RRS feed

  • Question

  • Is the EventLogWatcher class supported on Windows 2003? If not, is there a different class that can be used in place of it for the 2003 platform?

    I created a basic project to log events with EventLog and another to monitor logged events with EventLogWatcher. The programs work correctly on my Windows 7 pc but when the projects are remotely debugged on a Windows 2003 pc (using VS Remote Debugging Monitor) an error occurs on the watcher program. When the EventLogMonitor object Enabled parameter is set to "true" (watcher.Enabled = true;) the following exception is sent:

    PlatformNotSupportedException was caught:
    Operation is not supported on this platform.

    Monday, July 25, 2011 3:38 PM

Answers

  • The various server products use different methodologies for listening to events...the EventLogWatcher is specific to Server 2008, Server 2003 uses the EntryWrittenEventHandler.  The following code was an old method I used to listen to backup events...not even sure what I used it for, but amazingly I still had it handy...perhaps it'll help a little:

        private void RunListener(string opperatingSystem)
        {
          switch (opperatingSystem)
          {
            case "Server 2008":
              EventLogQuery eq = new EventLogQuery("Microsoft-Windows-Backup", PathType.LogName, "*[System/Provider/@Name=\"Microsoft-Windows-Backup\"]");
              EventLogWatcher elw = new EventLogWatcher(eq);
              elw.EventRecordWritten += new EventHandler<EventRecordWrittenEventArgs>(elw_EventRecordWritten);
              elw.Enabled = true;
              break;
            case "Server 2003":
              EventLog el2003 = new EventLog("Backup");
              el2003.EntryWritten += new EntryWrittenEventHandler(el_EntryWritten);
              el2003.EnableRaisingEvents = true;
              break;
            default:
              //Unsupported Opperating System!
              break;
          }
        }
    
    


    Hope it helps,

    Aj


    If at first you don't succeed, skydiving is definitely not for you!
    • Proposed as answer by aaj23 Monday, July 25, 2011 6:37 PM
    • Marked as answer by cdsoldev Monday, July 25, 2011 6:56 PM
    Monday, July 25, 2011 6:33 PM

All replies

  • The various server products use different methodologies for listening to events...the EventLogWatcher is specific to Server 2008, Server 2003 uses the EntryWrittenEventHandler.  The following code was an old method I used to listen to backup events...not even sure what I used it for, but amazingly I still had it handy...perhaps it'll help a little:

        private void RunListener(string opperatingSystem)
        {
          switch (opperatingSystem)
          {
            case "Server 2008":
              EventLogQuery eq = new EventLogQuery("Microsoft-Windows-Backup", PathType.LogName, "*[System/Provider/@Name=\"Microsoft-Windows-Backup\"]");
              EventLogWatcher elw = new EventLogWatcher(eq);
              elw.EventRecordWritten += new EventHandler<EventRecordWrittenEventArgs>(elw_EventRecordWritten);
              elw.Enabled = true;
              break;
            case "Server 2003":
              EventLog el2003 = new EventLog("Backup");
              el2003.EntryWritten += new EntryWrittenEventHandler(el_EntryWritten);
              el2003.EnableRaisingEvents = true;
              break;
            default:
              //Unsupported Opperating System!
              break;
          }
        }
    
    


    Hope it helps,

    Aj


    If at first you don't succeed, skydiving is definitely not for you!
    • Proposed as answer by aaj23 Monday, July 25, 2011 6:37 PM
    • Marked as answer by cdsoldev Monday, July 25, 2011 6:56 PM
    Monday, July 25, 2011 6:33 PM
  • By the way, something to possibly save you time if you plan to use this on various different server versions:

     

        private string DetectOpperatingSystem()
        {
          OperatingSystem os = Environment.OSVersion;
          int majorVersion = os.Version.Major;
          int minorVersion = os.Version.Minor;
    
          if(majorVersion == 6 && (minorVersion == 0 || minorVersion == 1))
          {
            return "Server 2008";
          }
          else if (majorVersion == 5 && minorVersion == 2)
          {
            return "Server 2003";  
          }
          else if (majorVersion == 5 && minorVersion == 0)
          {
            return "Server 2000";
          }
          else
          {
            return "Unsuported";
          }
        }
    


    Hope it helps,

    Aj


    If at first you don't succeed, skydiving is definitely not for you!
    Monday, July 25, 2011 6:37 PM