private void Launch_Handler(object sender, ExecutedRoutedEventArgs e)
 {
     RichtextBox.AppendText(textBox.Text);
     using (System.IO.StreamWriter writer = new System.IO.StreamWriter("log.txt", true))
     {
         writer.WriteLine("Внесено {0}: {1} ", textBox.Text, DateTime.Now.ToShortDateString() + ", время: " +
                          DateTime.Now.ToLongTimeString());
         writer.Flush();
     }
 }
예제 #2
0
 /// <summary>
 /// This method is called by the <see cref="AppenderSkeleton.DoAppend(log4net.Core.LoggingEvent)"/> method.
 /// </summary>
 /// <param name="LoggingEvent">The event to log.</param>
 /// <remarks>
 /// <para>
 /// Writes the event to the RichTextBox control, if set.
 /// </para>
 /// <para>
 /// The format of the output will depend on the appender's layout.
 /// </para>
 /// <para>
 /// This method can be called from any thread.
 /// </para>
 /// </remarks>
 protected override void Append(LoggingEvent LoggingEvent)
 {
     if (RichtextBox != null)
     {
         if (RichtextBox.InvokeRequired)
         {
             RichtextBox.Invoke(
                 new UpdateControlDelegate(UpdateControl),
                 new object[] { LoggingEvent });
         }
         else
         {
             UpdateControl(LoggingEvent);
         }
     }
 }
예제 #3
0
        /// <summary>
        /// Add logging event to configured control
        /// </summary>
        /// <param name="loggingEvent">The event to log</param>
        private void UpdateControl(LoggingEvent loggingEvent)
        {
            // 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));
        }