public void Show() { HiveData.SyncWithStorage(HiveSyncFlags.LoadFromFile, true); long pid = HiveData.ManagedData.Pid; int port = HiveData.ManagedData.LocalLogWatchPort; if (pid != 0 && port != 0) { Con.WriteLine("Starting the real-time log session."); Con.WriteLine("Pressing Ctrl + D or Ctrl + Q to disconnect the session."); Con.WriteLine(); Con.WriteLine($"Connecting to localhost:{port} ..."); CancellationTokenSource cancelSource = new CancellationTokenSource(); CancellationToken cancel = cancelSource.Token; Task task = TaskUtil.StartAsyncTaskAsync(async() => { try { using (var sock = await LocalNet.ConnectAsync(new TcpConnectParam(IPAddress.Loopback, port), cancel)) using (var stream = sock.GetStream()) using (MemoryHelper.FastAllocMemoryWithUsing(65536, out Memory <byte> tmp)) { Con.WriteLine("The real-time log session is connected."); Con.WriteLine(); try { while (true) { int r = await stream.ReadAsync(tmp, cancel); if (r <= 0) { break; } ReadOnlyMemory <byte> data = tmp.Slice(0, r); string s = Str.Utf8Encoding.GetString(data.Span); Console.Write(s); } } catch { } Con.WriteLine(); Con.WriteLine("The real-time log session is disconnected."); } } catch (Exception ex) { Con.WriteError(ex.Message); } }); try { while (true) { var key = Console.ReadKey(); if ((key.Key == ConsoleKey.D || key.Key == ConsoleKey.Q) && key.Modifiers == ConsoleModifiers.Control) { break; } } } catch { } cancelSource._TryCancelNoBlock(); task._TryWait(true); } else { Con.WriteLine($"The daemon \"{Name}\" is not running."); } }