Is there a way to programatically find EventLogs and the Windows Services that generated them?

33 Views Asked by At

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!

0

There are 0 best solutions below