private void Redirect(StreamReader input, StreamReader inputError, TextBlock output)
        {
            output.Text = string.Empty;
            new Thread(a =>
            {
                while (!input.EndOfStream)
                {
                    var line = input.ReadLine();
                    output.Dispatcher.Invoke(new Action(delegate
                    {
                        output.Text += line + Environment.NewLine;
                        ConsoleScroller.ScrollToBottom();
                    }));
                }
                ;
            }).Start();

            new Thread(a =>
            {
                while (!inputError.EndOfStream)
                {
                    var line = inputError.ReadLine();
                    output.Dispatcher.Invoke(new Action(delegate
                    {
                        output.Text += line + Environment.NewLine;
                        ConsoleScroller.ScrollToBottom();
                    }));
                }
                ;
            }).Start();
        }
 private void ItemsControl_SizeChanged(object sender, SizeChangedEventArgs e)
 {
     // Scroll to bottom only when the scroll is on the bottom
     if (ConsoleScroller.VerticalOffset == ConsoleScroller.ScrollableHeight)
     {
         ConsoleScroller.ScrollToBottom();
     }
 }
Exemple #3
0
 private void Logger_CustomLogging(LoggerArgs e)
 {
     if (e.Level <= _maxLogLevel)
     {
         // https://stackoverflow.com/a/18331866/1934487
         uiContext.Post(x =>
         {
             dc.ConsoleOutput.Add(e);
             //dc.ConsoleOutput.Add(bot.GetCurrentPosition().X);
             ConsoleScroller.ScrollToBottom();
         }, null);
     }
 }
 public void AddLine(string logItem)
 {
     try
     {
         TextBlock line = new TextBlock();
         line.Text       = logItem;
         line.Foreground = Brushes.White;
         Console.Children.Add(line);
         ConsoleScroller.ScrollToBottom();
     }
     catch (Exception ex)
     {
         ErrorLogger.GenerateErrorRecord(ex);
     }
 }
        public ConsoleLog(ObservableCollectionLoggerProvider loggerProvider)
        {
            InitializeComponent();

            loggerProvider.LogBuffer.CollectionChanged += (s, e) => Dispatcher.Invoke(() =>
            {
                if (e.Action == NotifyCollectionChangedAction.Add)
                {
                    foreach (object item in e.NewItems)
                    {
                        ConsoleOutput.Add(item.ToString());
                    }

                    ConsoleScroller.ScrollToBottom();
                }
            });
        }
Exemple #6
0
        public void Write(string msg, int level)
        {
            string color = "White";

            if (level == 1)
            {
                color = "Yellow";
            }
            else if (level == 0)
            {
                color = "Red";
            }
            App.Current?.Dispatcher.Invoke(delegate
            {
                AllConsoleLogs.Add(new ConsoleEntry()
                {
                    Text = msg, Color = color
                });
                if (AllConsoleLogs.Count > MaxLogSize)
                {
                    AllConsoleLogs.RemoveAt(0);
                }
                if (msg.IndexOf(FilterTextBox.Text) >= 0)
                {
                    ConsoleLog.ConsoleOutput.Add(new ConsoleEntry()
                    {
                        Text = msg, Color = color
                    });
                    if (ConsoleLog.ConsoleOutput.Count > MaxLogSize)
                    {
                        ConsoleLog.ConsoleOutput.RemoveAt(0);
                    }
                }
                if (ConsoleScrollToBottom)
                {
                    ConsoleScroller.ScrollToBottom();
                }
            });
        }