using System; using System.Diagnostics; using Microsoft.Extensions.DiagnosticAdapter; public class MyClass { [DiagnosticName("MyCustomEvent")] public void MyCustomEvent(string message) { Console.WriteLine($"MyCustomEvent raised with message: {message}"); } public void DoSomething() { using (DiagnosticListener listener = new DiagnosticListener("MyListener")) { listener.Subscribe(new MyClass()); using (DiagnosticScope scope = listener.BeginScope("MyCustomEvent")) { // Do something here scope.SetTag("Tag1", "Value1"); scope.SetTag("Tag2", "Value2"); listener.Write("MyCustomEvent", "Hello"); } } } }In this example, we define a custom event called "MyCustomEvent" using the DiagnosticName attribute. We then create a DiagnosticListener and subscribe an instance of MyClass to it. Inside the DoSomething method, we start a DiagnosticScope with the name "MyCustomEvent". We then set some tags on the scope and write the event using the DiagnosticListener. Package Library: Microsoft.Extensions.DiagnosticAdapter.