Created
December 4, 2018 15:36
-
-
Save richlander/bfc5939162d566bbd84139e7b9ddfa3d to your computer and use it in GitHub Desktop.
.NET Runtime Events API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"); | |
| } | |
| } |
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
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.