C# DiagnosticSource and DiagnosticListener
阿新 • • 發佈:2020-08-19
class Program { private static readonly DiagnosticSource testDiagnosticListener = new DiagnosticListener("TestDiagnosticListener"); public static void Main() { DiagnosticListener.AllListeners.Subscribe(new CurrentConditionDisplay()); testDiagnosticListener.Write("RequestStart", "hello world"); var httpClient =new HttpClient(); var response = httpClient.GetAsync("http://www.mingdao.com").Result; var result = response.Content.ReadAsStringAsync().Result; } } class CurrentConditionDisplay : IObserver<DiagnosticListener> {public void OnCompleted() { } public void OnError(Exception error) { // Method intentionally left empty. } public void OnNext(DiagnosticListener value) { value.Subscribe(new DiagnosticEventObserver()); } }public class DiagnosticEventObserver : IObserver<KeyValuePair<string, object>> { public void OnCompleted() { // Method intentionally left empty. } public void OnError(Exception error) { // Method intentionally left empty. } public void OnNext(KeyValuePair<string, object> value) { } }
reference ->https://www.jianshu.com/p/a1eb1c0aa1ef