public async Task <int> OnExecuteAsync(CommandLineApplication app, IConsole console) { var cancellationToken = console.GetCtrlCToken(); if (string.IsNullOrEmpty(Target)) { console.Error.WriteLine("Missing required option: --server"); return(1); } if (!EndPointParser.TryParseEndpoint(Target, out var endPoint)) { console.Error.WriteLine($"Invalid server value: {Target}"); return(1); } var client = new DiagnosticsClient(endPoint); console.WriteLine("Connecting to application..."); client.OnEventSourceCreated += (eventSource) => { console.WriteLine($"* {eventSource.Name} [{eventSource.Guid}] (settings: {eventSource.Settings})"); }; await client.ConnectAsync(); console.WriteLine("Connected, press Ctrl-C to terminate..."); await cancellationToken.WaitForCancellationAsync(); return(0); }
public async Task <int> OnExecuteAsync(CommandLineApplication app, IConsole console) { System.Threading.CancellationToken cancellationToken = console.GetCtrlCToken(); EndPoint endPoint; if (ProcessId is int pid) { ProcessRegistration reg = await ProcessLocator.GetRegistrationAsync(pid); endPoint = new IPEndPoint(IPAddress.Loopback, reg.DiagnosticsPort); } else { if (string.IsNullOrEmpty(Target)) { console.Error.WriteLine("Missing required option: --server"); return(1); } if (!EndPointParser.TryParseEndpoint(Target, out endPoint)) { console.Error.WriteLine($"Invalid server value: {Target}"); return(1); } } if (Providers.Count == 0) { console.Error.WriteLine("No providers were listed"); return(1); } var client = new DiagnosticsClient(endPoint); console.WriteLine("Connecting to application..."); client.OnEventWritten += (evt) => { var formattedMessage = string.Format(evt.Message, evt.Payload.ToArray()); console.WriteLine($"{evt.ProviderName}/{evt.EventName}({evt.EventId}): {formattedMessage}"); }; await client.ConnectAsync(); await client.EnableEventsAsync(Providers.Select(p => new EnableEventsRequest(p, EventLevel.Verbose, EventKeywords.All))); console.WriteLine("Connected, press Ctrl-C to terminate..."); await cancellationToken.WaitForCancellationAsync(); return(0); }