Exemplo n.º 1
0
        private void ProcessStandardOutput(object sender, DataReceivedEventArgs args)
        {
            if (args == null || string.IsNullOrWhiteSpace(args.Data))
            {
                return;
            }

            // Fire event when Ngrok Client Session is established
            const string clientSessionEstablishedKey = "obj=csess";

            if (args.Data.Contains(clientSessionEstablishedKey))
            {
                ProcessStarted?.Invoke();
            }

            if (_options.RedirectLogs)
            {
                // Build structured log data
                var data          = NgrokLogExtensions.ParseLogData(args.Data);
                var logFormatData = data.Where(d => d.Key != "lvl" && d.Key != "t")
                                    .ToDictionary(e => e.Key, e => e.Value);
                var logFormatString = NgrokLogExtensions.GetLogFormatString(logFormatData);
                var logLevel        = NgrokLogExtensions.ParseLogLevel(data["lvl"]);

                _ngrokProcessLogger.Log(logLevel, logFormatString, logFormatData.Values.ToArray());
            }
        }
        public void ParseMisc()
        {
            var input          = "t=2020-03-02T00:44:26-0600 lvl=info msg=\"no configuration paths supplied\"";
            var expectedResult = new Dictionary <string, string>()
            {
                { "t", "2020-03-02T00:44:26-0600" },
                { "lvl", "info" },
                { "msg", "no configuration paths supplied" }
            };

            var result = NgrokLogExtensions.ParseLogData(input);

            Assert.Equal(expectedResult, result);
        }
        public void ParseStartTunnel()
        {
            var input          = "t=2020-03-01T23:36:39-0600 lvl=info msg=\"started tunnel\" obj=tunnels name=test_tunnel addr=http://localhost:425 url=https://12030abc.ngrok.io";
            var expectedResult = new Dictionary <string, string>()
            {
                { "t", "2020-03-01T23:36:39-0600" },
                { "lvl", "info" },
                { "msg", "started tunnel" },
                { "obj", "tunnels" },
                { "name", "test_tunnel" },
                { "addr", "http://localhost:425" },
                { "url", "https://12030abc.ngrok.io" }
            };
            var result = NgrokLogExtensions.ParseLogData(input);

            Assert.Equal(expectedResult, result);
        }