title: Need a Way to Search through Event Logs by RecordID
body: <p>I am trying to search through a folder with Event Logs in them, eventpath has the path of the specific Event Log I want to access. I want to use a specified RecordID to find it's correlated FormatDescription and display it in a MessageBox. I want to be able to use the eventpath to access each Event Log since I am using 6 separate .evtx files and need to use this method on all of them.</p>
  <p>I found this solution, but I get an error when I'm trying to Query. I've tried to find a fix, but it seems as if it's just not going to work for what I need. I commented where exactly it is occurring in the code.</p>
  <p>This is the exception: System.Diagnostics.Eventing.Reader.EventLogException: The specified path is invalid.</p>
  <p><em><strong>I can't find a fix for this code, but if anyone knows a fix or another way to approach searching through Event Logs by RecordID and giving the corresponding FormatDescription, it would be greatly appreciated.</strong></em></p>
  <p>I am using C# in Windows Presentation Foundation.</p>
  <pre><code>public void getDesc(string recordid)
          {
  
              string eventpath = getEventPath();
         
              //takes off the .evtx of the path
              string result = eventpath.Substring(0, eventpath.Length - 5);
             //result1 is going to be similar to this:
             //C:\Users\MyName\AppData\Local\Temp\randomTempDirectory\additional_files\DiagnosticInfo\WindowsEventLogs\Application
  
              string sQuery = &quot;*[System/EventRecordID=&quot; + recordid + &quot;]&quot;;
             
              var elQuery = new EventLogQuery(result, PathType.LogName, sQuery);
            
              //this is where it errors out
              //error: Specified Channel Path is invalid
              using (var elReader = new System.Diagnostics.Eventing.Reader.EventLogReader(elQuery))
              {
  
                  List&lt;EventRecord&gt; eventList = new List&lt;EventRecord&gt;();
                  EventRecord eventInstance = elReader.ReadEvent();
                  try
                  {
                      while ((eventInstance = elReader.ReadEvent()) != null)
                      {
                          //Access event properties here:
           
                          string formatDescription = eventInstance.FormatDescription();
                          MessageBox.Show(formatDescription);
                      }
                  }
                  finally
                  {
                      if (eventInstance != null)
  
                          eventInstance.Dispose();
  
                  }
              }
              
  
          } 
  </code></pre>