コード例 #1
0
        public static TcpLogListener Start(int port, bool dontLogToConsole = false)
        {
            var encoding = Encoding.UTF8;
            var lines    = new ConcurrentQueue <string>();

            Task OnProcessLineAsync(string line)
            {
                line = line.TrimEnd(NewLineChars);
                lines.Enqueue(line);
                if (!dontLogToConsole)
                {
                    TestLogger.Log($"[TCPLOG] {line}");
                }
                return(Task.CompletedTask);
            }

            var listener =
                SimpleTcpListener.Start(port, backlog: 1,
                                        (_, stream) => stream.ProcessLinesAsync(encoding, OnProcessLineAsync));

            try
            {
                var logListener = new TcpLogListener(listener, lines);
                TestLogger.Log($"*** TCP Log Listener created: {IPAddress.Any}:{port} ***");
                return(logListener);
            }
            catch (Exception)
            {
                listener.Dispose();
                throw;
            }
        }
コード例 #2
0
 private TcpLogListener(SimpleTcpListener listener, ConcurrentQueue <string> events)
 {
     this.listener = listener;
     this.events   = events;
 }