0

I'm using C# in Visual Studio 2019. I'm trying to get to list of all Windows Services currently on the system, which I successfully got, then get the EventLogs associated with those services, which I haven't been able to.

I'm able to get all services, I'm able to get all event logs.

    ServiceController[] all = ServiceController.GetServices();
    foreach (ServiceController item in all)
    {
        Console.WriteLine(item.ServiceName);
        Console.WriteLine(item.DisplayName);
        Console.WriteLine("-------------------------------");
    }
    EventLog[] eventLogs = EventLog.GetEventLogs();

I've been trying to find some way to connect the two but I'm not coming up with anything meaningful.

I was hoping to find a way to map service-to-log or log-to-service.

Any help would be appreciated. Thanks!

Abdullah
  • 133
  • 1
  • 2
  • 10
  • 1
    An `EventLog` can have multiple sources. Have you tried to use the `EventLogEntry.Source` property of the log entries (`EventLog.Entries`)? – dymanoid Jul 18 '19 at 21:01
  • @dymanoid Yes, I look in there but found no entries linking back to the services. Either that, or I'm missing something critical.. I feel I'm so close to getting it – Abdullah Jul 18 '19 at 21:45
  • You might need to use ```System``` as a source. Most of the services run in System user. – Pulathisi Bandara Jul 25 '19 at 09:31

0 Answers0