1

This is an asp.net application using framework 4.7.

I'm attempting to attach to the Microsoft.IdentityModel.Logging.IdentityModelEventSource.Logger in an asp.net application (I'm using OpenIdConnect in an OWIN startup class, I am having problems and am hoping that attaching to this logger might give me some clues).

In my OWIN Startup class, in the Configuration() method, I have the following:

     Microsoft.IdentityModel.Logging.IdentityModelEventSource.Logger.LogLevel = System.Diagnostics.Tracing.EventLevel.Verbose;
            Microsoft.IdentityModel.Logging.IdentityModelEventSource.ShowPII = true;
            var listener = new EventListener();
            listener.EnableEvents(Microsoft.IdentityModel.Logging.IdentityModelEventSource.Logger, EventLevel.LogAlways);
            listener.EventWritten += Listener_EventWritten;
            Microsoft.IdentityModel.Logging.IdentityModelEventSource.Logger.WriteVerbose("A test message.");

And in my Listener_EventWritten method I have the following:

private void Listener_EventWritten(object sender, EventWrittenEventArgs e)
    {
        Debug.WriteLine(e.EventName + "," + e.Message);
    }

This method fires a bunch of times, but "e.Message" is always null. What am I doing wrong?

Tom Regan
  • 3,580
  • 4
  • 42
  • 71

1 Answers1

2

The message is in e.Payload.

So try to change Your code to:

private void Listener_EventWritten(object sender, EventWrittenEventArgs e)
{
    foreach (object payload in e.Payload)
    {
        Debug.WriteLine($"[{e.EventName}] {e.Message} | {payload}");
    }
}

It works for me correctly.

Pawel
  • 280
  • 3
  • 10