Ejemplo n.º 1
0
		public MainForm()
		{
			InitializeComponent();
			
			if (!Global.logger.Logger.Repository.Configured)
			{
				rba = new RichTextBoxAppender(richTextBoxLog);
				rba.Threshold = Level.All;
				rba.Layout = new PatternLayout("%date{dd-MM-yyyy HH:mm:ss.fff} %5level %message %n");
				LevelTextStyle ilts = new LevelTextStyle();
				ilts.Level = Level.Info;
				ilts.TextColor = Color.Yellow;
				ilts.PointSize = 10.0f;
				rba.AddMapping(ilts);
				LevelTextStyle dlts = new LevelTextStyle();
				dlts.Level = Level.Debug;
				dlts.TextColor = Color.LightBlue;
				dlts.PointSize = 10.0f;
				rba.AddMapping(dlts);
				LevelTextStyle wlts = new LevelTextStyle();
				wlts.Level = Level.Warn;
				wlts.TextColor = Color.Chartreuse;
				wlts.PointSize = 10.0f;
				rba.AddMapping(wlts);
				LevelTextStyle elts = new LevelTextStyle();
				elts.Level = Level.Error;
				elts.TextColor = Color.Crimson;
				elts.BackColor = Color.Cornsilk;
				elts.PointSize = 10.0f;
				rba.AddMapping(elts);
				
				BasicConfigurator.Configure(rba);
				rba.ActivateOptions();
				mba = new MessageBoxAppender();
				mba.Layout = new PatternLayout("%date{dd-MM-yyyy HH:mm:ss.fff} %5level %message %n");
				mba.Threshold = Level.Error;
				BasicConfigurator.Configure(mba);
				mba.ActivateOptions();
				
				RollingFileAppender fa = new RollingFileAppender();
				fa.AppendToFile = true;
				fa.Threshold = log4net.Core.Level.All;
				fa.RollingStyle = RollingFileAppender.RollingMode.Size;
				fa.MaxFileSize = 100000;
				fa.MaxSizeRollBackups = 3;
				fa.File = dskPath + @"\FgPleoraLog.txt";
				fa.Layout = new log4net.Layout.PatternLayout("%date{dd-MM-yyyy HH:mm:ss.fff} %5level %message (%logger{1}:%line)%n");
				log4net.Config.BasicConfigurator.Configure(fa);
				fa.ActivateOptions();
			}
		}
Ejemplo n.º 2
0
        /// <summary>
        /// Add logging event to configured control
        /// </summary>
        /// <param name="loggingEvent">The event to log</param>
        private void UpdateControl(LoggingEvent loggingEvent)
        {
            if (_richtextBox.IsDisposed)
            {
                return;
            }

            // There may be performance issues if the buffer gets too long
            // So periodically clear the buffer
            if (_richtextBox.TextLength > _maxTextLength)
            {
                _richtextBox.Clear();
                _richtextBox.AppendText(string.Format("(earlier messages cleared because log length exceeded maximum of {0})\n\n", _maxTextLength));
            }

            // look for a style mapping
            LevelTextStyle selectedStyle = _levelMapping.Lookup(loggingEvent.Level) as LevelTextStyle;

            if (selectedStyle != null)
            {
                // set the colors of the text about to be appended
                _richtextBox.SelectionBackColor = selectedStyle.BackColor;
                _richtextBox.SelectionColor     = selectedStyle.TextColor;

                // alter selection font as much as necessary
                // missing settings are replaced by the font settings on the control
                if (selectedStyle.Font != null)
                {
                    // set Font Family, size and styles
                    _richtextBox.SelectionFont = selectedStyle.Font;
                }
                else if (selectedStyle.PointSize > 0 && _richtextBox.Font.SizeInPoints != selectedStyle.PointSize)
                {
                    // use control's font family, set size and styles
                    float size = selectedStyle.PointSize > 0.0f ? selectedStyle.PointSize : _richtextBox.Font.SizeInPoints;
                    _richtextBox.SelectionFont = new Font(_richtextBox.Font.FontFamily.Name, size, selectedStyle.FontStyle);
                }
                else if (_richtextBox.Font.Style != selectedStyle.FontStyle)
                {
                    // use control's font family and size, set styles
                    _richtextBox.SelectionFont = new Font(_richtextBox.Font, selectedStyle.FontStyle);
                }
            }

            _richtextBox.AppendText(RenderLoggingEvent(loggingEvent));
        }
 /// <summary>
 /// Add a mapping of level to text style - done by the config file
 /// </summary>
 /// <param name="mapping">The mapping to add</param>
 /// <remarks>
 /// <para>
 /// Add a <see cref="LevelTextStyle"/> mapping to this appender.
 /// Each mapping defines the text style for a level.
 /// </para>
 /// </remarks>
 public void AddMapping(LevelTextStyle mapping)
 {
     _levelMapping.Add(mapping);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Add a mapping of level to text style - done by the config file
 /// </summary>
 /// <param name="mapping">The mapping to add</param>
 /// <remarks>
 /// <para>
 /// Add a <see cref="LevelTextStyle"/> mapping to this appender.
 /// Each mapping defines the text style for a level.
 /// </para>
 /// </remarks>
 public void AddMapping(LevelTextStyle mapping)
 {
     _levelMapping.Add(mapping);
 }