Search code examples
c#event-logevent-viewer

How to get List of all Providers in Event Viewer using C#?


I would like to get all the provider names of Event Viewer using C#. Please see below the sample provider

<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
  <Provider Name="Microsoft-Team Foundation Server" Guid="{80761876-6844-47D5-8106-F8ED2AA8687B}" />!`<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
  <Provider Name="Microsoft-Team Foundation Server" Guid="{80761876-6844-47D5-8106-F8ED2AA8687B}" />

How can I get these providers list?


Solution

  • Use the EventLogSession.GetProviderNames method like this:

    EventLogSession session = new EventLogSession();
    
    var providers = session.GetProviderNames().ToList();