EventLogReader and EventRecord: Where's the Message?
Asked Answered
A

1

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??
        }
    }
Availability answered 12/9, 2012 at 2:53 Comment(3)
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.Stonewall
@Stonewall I just figured it out and posted the answer. Thanks for your help.Availability
Yeah, it's too bad there no documentation on this in MSDN. Sorry for only stabbing in the dark :-PStonewall
A
23

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

Availability answered 12/9, 2012 at 3:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.