0

I'm running this kind of code to get local server logs, and it works as expected:

EventLog log = new EventLog("Security");
var entries = log.Entries.Cast<EventLogEntry>().Where(x => x.InstanceId == 4648).Select(x => new
                {
                    x.Message,
                    x.TimeGenerated
                }).ToList();

But I would like to get the logs from another server as well and concatenate the results. How can I contact the other server with c# and execute the same kind of code in the same application?

Many thanks in advance for your answers

imsome1
  • 1,182
  • 4
  • 22
  • 37
Jan
  • 253
  • 1
  • 13
  • 1
    I think you just pass the server name in the Event log constructor as the second parameter. Keep in mind permissions. Is the Application running under context that it would be able to access event log information on other machines. – Bearcat9425 Feb 14 '17 at 14:13
  • Ok, will try that. Normally the account under which the application runs is the same for both servers. Thank you. – Jan Feb 14 '17 at 14:57
  • It works! Many thanks! – Jan Feb 14 '17 at 16:24
  • No problem! Glad it worked I suppose I could have added an Answer. – Bearcat9425 Feb 14 '17 at 16:27

1 Answers1

0

The answer was

EventLog log = new EventLog("Security", "SERVERNAME");

Thanks to Bearcat9425 !

Jan
  • 253
  • 1
  • 13