views:

83

answers:

2

I want to create an app to monitor the event logs of multiple servers remotely all is good however the servers are likely to be offline now and again.

When i connect to a remote event log and the connection to the machine is lost a System.IO.IOException is thrown, I would like to hadle the error by connecting again to the remote server but since the EventLog class does not have a connect method I will have to create an new instance of EventLog and work out which EventLog instance threw the exception.

What is the best way to handle this scenario?

A: 

you could create a class ManagedEventLog where you store the eventlog connection and an id if the connection is lost and the exception is thrown you can see which id belongs to that connection and can call a reconnect method on the ManagedEventLog class.

Gambrinus
+2  A: 

You can get the log name and machine name from the EventLog instance that throws the exception, and then re-initialize that failing instance with those details.

As for storing the EventLog instances, use a List<> or Dictionary<>, which will allow you to enumerate over all EventLogs you're currently monitoring.

Ian Kemp