Ejemplo n.º 1
0
        private IDisposable CreateRichTextBoxFormatter(ThreadSafeRichTextBoxWrapper textboxWrapper, Color foreColor, Color backColor, FontStyle style)
        {
            Font font = new Font(textboxWrapper.Font, style);
            RichTextBoxFormatter formatter = new RichTextBoxFormatter(textboxWrapper, foreColor, backColor, font);

            return(new DisposableList(formatter, font));
        }
        private void Initialize()
        {
            ThreadSafeTextBoxWrapper wrapper = null;

            if (tb is RichTextBox)
            {
                wrapper = new ThreadSafeRichTextBoxWrapper((RichTextBox)tb);
            }
            else
            {
                wrapper = new ThreadSafeTextBoxWrapper(tb);
            }

            var logService = This.Logger;

            if ((logService != null) && (logService is ITextBoxAppendable))
            {
                var log = (ITextBoxAppendable)logService;
                appender = log.AddLogBox(wrapper, "%date [%thread] (%logger) %-8level- %message%newline");
                if (appender != null)
                {
                    appender.LogThreshold = SelectedLevel;
                }
            }

            var levels = new List <LogLevel>();

            levels.AddRange(Enums <LogLevel> .Values);
            levels.Sort((l1, l2) => (int)l1 - (int)l2);
            levels.ForEach(level => logLevelList.Items.Add(level));

            //TODO: select the log level depending on a settings file.
            logLevelList.SelectedItem = selectedLevel;

            foreach (ToolStripItem item in cm.Items)
            {
                items.Add(item);
            }
            foreach (ToolStripItem item in ts.Items)
            {
                if ((item != logLeveltoolStripLabel) && (item != logLevelList) && (item != toggleWordWrapToolStripButton))
                {
                    items.Add(item);
                }
            }

            UpdateToolStripItems();

            tb.TextChanged += (s, e) => UpdateToolStripItems();
            tb.LinkClicked += (s, e) =>
            {
                // We send the event to our parent.
                if (LinkClicked != null)
                {
                    LinkClicked(this, e);
                }
            };
        }
Ejemplo n.º 3
0
 private IDisposable CreateRichTextBoxFormatter(ThreadSafeRichTextBoxWrapper textboxWrapper, Color foreColor, Color backColor)
 {
     return(new RichTextBoxFormatter(textboxWrapper, foreColor, backColor));
 }
Ejemplo n.º 4
0
 private IDisposable CreateRichTextBoxFormatter(ThreadSafeRichTextBoxWrapper textboxWrapper, Color foreColor)
 {
     return(CreateRichTextBoxFormatter(textboxWrapper, foreColor, Color.Empty));
 }
Ejemplo n.º 5
0
        private IDisposable GetFormat(ThreadSafeRichTextBoxWrapper textboxWrapper, LoggingEvent loggingEvent)
        {
            if (loggingEvent.Level == Level.All)
            {
                return(new TrivialDisposable());
            }

            if ((loggingEvent.Level == Level.Verbose) || (loggingEvent.Level == Level.Finest))
            {
                return(CreateRichTextBoxFormatter(textboxWrapper, Color.Blue));
            }
            if ((loggingEvent.Level == Level.Trace) || (loggingEvent.Level == Level.Finer))
            {
                return(CreateRichTextBoxFormatter(textboxWrapper, Color.Blue, FontStyle.Bold | FontStyle.Underline));
            }
            if ((loggingEvent.Level == Level.Debug) || (loggingEvent.Level == Level.Fine))
            {
                return(CreateRichTextBoxFormatter(textboxWrapper, Color.Blue, FontStyle.Bold));
            }

            if (loggingEvent.Level == Level.Info) // Black on White
            {
                return(new TrivialDisposable());
            }

            if (loggingEvent.Level == Level.Notice)
            {
                return(CreateRichTextBoxFormatter(textboxWrapper, Color.Orange));
            }
            if (loggingEvent.Level == Level.Warn)
            {
                return(CreateRichTextBoxFormatter(textboxWrapper, Color.Orange, FontStyle.Bold));
            }

            if (loggingEvent.Level == Level.Error)
            {
                return(CreateRichTextBoxFormatter(textboxWrapper, Color.Red));
            }
            if (loggingEvent.Level == Level.Severe)
            {
                return(CreateRichTextBoxFormatter(textboxWrapper, Color.Red, FontStyle.Bold));
            }
            if (loggingEvent.Level == Level.Critical)
            {
                return(CreateRichTextBoxFormatter(textboxWrapper, Color.Red, FontStyle.Bold | FontStyle.Underline));
            }

            if (loggingEvent.Level == Level.Alert)
            {
                return(CreateRichTextBoxFormatter(textboxWrapper, Color.White, Color.Red));
            }
            if (loggingEvent.Level == Level.Fatal)
            {
                return(CreateRichTextBoxFormatter(textboxWrapper, Color.White, Color.Red, FontStyle.Bold));
            }
            if (loggingEvent.Level == Level.Emergency)
            {
                return(CreateRichTextBoxFormatter(textboxWrapper, Color.White, Color.Red, FontStyle.Bold | FontStyle.Underline));
            }

            return(new TrivialDisposable());
        }
Ejemplo n.º 6
0
 private void AppendRich(ThreadSafeRichTextBoxWrapper textboxWrapper, LoggingEvent loggingEvent)
 {
     using (GetFormat(textboxWrapper, loggingEvent)) AppendNormal(textboxWrapper, loggingEvent);
 }
        private void Initialize()
        {
            ThreadSafeTextBoxWrapper wrapper = null;
            if (tb is RichTextBox) wrapper = new ThreadSafeRichTextBoxWrapper((RichTextBox)tb);
            else wrapper = new ThreadSafeTextBoxWrapper(tb);

            var logService = This.Logger;
            if ((logService != null) && (logService is ITextBoxAppendable))
            {
                var log = (ITextBoxAppendable)logService;
                appender = log.AddLogBox(wrapper, "%date [%thread] (%logger) %-8level- %message%newline");
                if (appender != null) appender.LogThreshold = SelectedLevel;
            }

            var levels = new List<LogLevel>();
            levels.AddRange(Enums<LogLevel>.Values);
            levels.Sort((l1, l2) => (int)l1 - (int)l2);
            levels.ForEach(level => logLevelList.Items.Add(level));

            //TODO: select the log level depending on a settings file.
            logLevelList.SelectedItem = selectedLevel;

            foreach (ToolStripItem item in cm.Items) items.Add(item);
            foreach (ToolStripItem item in ts.Items)
            {
                if ((item != logLeveltoolStripLabel) && (item != logLevelList) && (item != toggleWordWrapToolStripButton))
                    items.Add(item);
            }

            UpdateToolStripItems();

            tb.TextChanged += (s, e) => UpdateToolStripItems();
            tb.LinkClicked += (s, e) =>
            {
                // We send the event to our parent.
                if (LinkClicked != null) LinkClicked(this, e);
            };
        }