Skip to content

Instantly share code, notes, and snippets.

@richlander
Created December 4, 2018 15:36
Show Gist options
  • Select an option

  • Save richlander/bfc5939162d566bbd84139e7b9ddfa3d to your computer and use it in GitHub Desktop.

Select an option

Save richlander/bfc5939162d566bbd84139e7b9ddfa3d to your computer and use it in GitHub Desktop.
.NET Runtime Events API
internal sealed class SimpleEventListener : EventListener
{
// Called whenever an EventSource is created.
protected override void OnEventSourceCreated(EventSource eventSource)
{
// Watch for the .NET runtime EventSource and enable all of its events.
if (eventSource.Name.Equals("Microsoft-Windows-DotNETRuntime"))
{
EnableEvents(eventSource, EventLevel.Verbose, (EventKeywords)(-1));
}
}
// Called whenever an event is written.
protected override void OnEventWritten(EventWrittenEventArgs eventData)
{
// Write the contents of the event to the console.
Console.WriteLine($"ThreadID = {eventData.OSThreadId} ID = {eventData.EventId} Name = {eventData.EventName}");
for (int i = 0; i < eventData.Payload.Count; i++)
{
string payloadString = eventData.Payload[i] != null ? eventData.Payload[i].ToString() : string.Empty;
Console.WriteLine($"\tName = \"{eventData.PayloadNames[i]}\" Value = \"{payloadString}\"");
}
Console.WriteLine("\n");
}
}
@rustbomber
Copy link
Copy Markdown

MS announce the release of .NET Core 2.2. It includes diagnostic improvements to the runtime, with Runtime Events, My question is How to use EventListener in .net core 2.2, the article is poor.

@liguobao
Copy link
Copy Markdown

How to use it on .NET Core2.2 Web API.
The article is very poor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment