Skip to content

Instantly share code, notes, and snippets.

@MihaZupan
Created June 11, 2021 18:19
Show Gist options
  • Save MihaZupan/5e32cf3b4266f551714a75e1a1065331 to your computer and use it in GitHub Desktop.
Save MihaZupan/5e32cf3b4266f551714a75e1a1065331 to your computer and use it in GitHub Desktop.
using System;
using System.Diagnostics.Tracing;
using System.Linq;
using System.Net.Sockets;
using System.Threading.Tasks;
namespace RuntimeTesting
{
class Program
{
static async Task Main()
{
using var listener = new Listener();
using var socket = new Socket(SocketType.Stream, ProtocolType.Tcp);
await socket.ConnectAsync("foo.test", 443);
}
public class Listener : EventListener
{
protected override void OnEventSourceCreated(EventSource eventSource)
{
if (eventSource.Name == "System.Net.Sockets")
{
EnableEvents(eventSource, EventLevel.Informational);
}
}
protected override void OnEventWritten(EventWrittenEventArgs eventData)
{
Console.WriteLine($"{eventData.EventName}: {eventData.Payload.FirstOrDefault()}");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment