16

I want to query the Application Event Log on a remote machine and I resorted to using the EventLogReader rather than the EventLog because it takes way to long to find the events I need with the EventLog. However, even though it finds the events much faster with the EventLogReader, I can't figure out where the heck the info I need is on this object... especially the message.

    public static void Load()
    {
        string query = "*[System/Provider/@Name=\"SQLSERVERAGENT\"]";

        EventLogQuery elq = new EventLogQuery("Application", PathType.LogName, query);
        elq.Session = new EventLogSession("x.x.x.x");
        EventLogReader elr = new EventLogReader(elq);

        _logEntries = new List<SqlEventEntry>();

        EventRecord entry;
        while ((entry = elr.ReadEvent()) != null)
        {
            var Message = entry.???
            // I want process the message in the event here,
            // but I can't find a property anywhere that contains the message??
        }
    }
Liam
  • 27,717
  • 28
  • 128
  • 190
Brandon Moore
  • 8,590
  • 15
  • 65
  • 120
  • Again event viewer to the rescue. Is there one or more `entry.EventData` properties (either an enumerable called `Data` or just multiple named properties)? I'm stabbing in the dark a little, but you can also open eventvwr.msc, open a random event, and look at the XML view. – lc. Sep 12 '12 at 03:00
  • @lc. I just figured it out and posted the answer. Thanks for your help. – Brandon Moore Sep 12 '12 at 03:03
  • Yeah, it's too bad there no documentation on this in MSDN. Sorry for only stabbing in the dark :-P – lc. Sep 12 '12 at 03:07

1 Answers1

22

Sigh... It's the FormatDescription() method. I didn't see it because I was only looking at the properties.

Liam
  • 27,717
  • 28
  • 128
  • 190
Brandon Moore
  • 8,590
  • 15
  • 65
  • 120