private void Logger_OnLog(string messaeg)
 {
     Dispatcher.BeginInvoke(new Action(() =>
     {
         LogRichTextBox.AppendText(messaeg + Environment.NewLine);
         LogRichTextBox.ScrollToEnd();
     }));
 }
Beispiel #2
0
 private void UITimerCallBack(object sender, EventArgs e)
 {
     if (LogNewlines > 0)
     {
         LogNewlines = 0;
         LogRichTextBox.ScrollToEnd();
     }
 }
Beispiel #3
0
        public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter)
        {
            Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
            {
                var now = DateTimeOffset.Now;
                _paragraph.Inlines.Add(new Run(now.ToString("HH:mm:ss.ff") + " ")
                {
                    Foreground = _timeBrush
                });

                switch (eventId.Id)
                {
                case 1:
                    _paragraph.Inlines.Add(
                        new Run(Tx.T("DeployClientView:Messages.BuildSucceeded"))
                    {
                        Foreground = _succeededBrush, FontWeight = FontWeights.Bold
                    });
                    return;

                case -1:
                    _paragraph.Inlines.Add(
                        new Run(Tx.T("DeployClientView:Messages.OperationCancelled"))
                    {
                        Foreground = _cancelledBrush, FontWeight = FontWeights.Bold
                    });
                    return;

                case -2:
                    _paragraph.Inlines.Add(
                        new Run(Tx.T("DeployClientView:Messages.UnexpectedError"))
                    {
                        Foreground = _errorBrush, FontWeight = FontWeights.Bold
                    });
                    if (exception != null)
                    {
                        _paragraph.Inlines.Add(new LineBreak());
                        _paragraph.Inlines.Add(new Run(exception.ToString()));
                    }
                    return;
                }

                var brush  = _logLevelBrushes[logLevel];
                var prefix = logLevel.ToString().ToUpper();

                _paragraph.Inlines.Add(new Run($"[{prefix}] {formatter(state, exception)}")
                {
                    Foreground = brush
                });
                _paragraph.Inlines.Add(new LineBreak());

                LogRichTextBox.ScrollToEnd();
            }));
        }
        private void AddLog(LogEntry item)
        {
            var level     = item.Level;
            var paragraph = new Paragraph()
            {
                LineHeight = 1
            };
            var run = new Run(item.ToString())
            {
                Foreground = GetBrushForLevel(level)
            };

            paragraph.Inlines.Add(run);
            LogRichTextBox.Document.Blocks.Add(paragraph);
            LogRichTextBox.ScrollToEnd();
        }