1

I am trying to call FormatDescription(ienumerable) of an EventRecord but cannot get it to replace the strings. What am I doing wrong?

    public void StartLogReading()
    {          
        EventLogQuery evtLogQuery = new EventLogQuery(
            "Application",
            PathType.LogName,
            "*[System/EventRecordID >= 0]");

        var watcher = new EventLogWatcher(evtLogQuery, null, true);
        watcher.EventRecordWritten += EventLogEventRead;
        watcher.Enabled = true;

    }

    private void EventLogEventRead(object sender, EventRecordWrittenEventArgs e)
    {
        List<object> aParams = new List<object>();
        foreach (EventProperty eventProperty in e.EventRecord.Properties)
        {
            aParams.Add(eventProperty.Value);
        }
        string description = e.EventRecord.FormatDescription(aParams);
        // Do stuff with description
    }

The string description always contains the event message without the params being replaced.

I am actually trying to use this technique as a workaround for the exception I get sometimes: "The description string for parameter reference (%1) could not be found" when calling e.EventRecord.FormatDescription().

Pelle
  • 105
  • 7
  • I'm actually having a similar issue, and have filed a bug report with Microsoft, you may want to go upvote it for visibility and to increase the odds that it gets the attention necessary for a resolution: https://developercommunity.visualstudio.com/content/problem/385483/eventrecordformatdescriptionienumberable.html – OperatorOverload Nov 18 '18 at 19:53
  • Ok. Just upvoted. – Pelle Nov 19 '18 at 20:04

0 Answers0