John and Neils,

 

Thanks for the TextBoxAppender and RichTextBoxAppender.  They are exactly what I was looking for.  I have one suggestion though and that is to make the appenders thread safe.  When using controls, you need to use invoke to make sure to update the control on the same thread the control was created on.  See http://msdn.microsoft.com/library/default.asp?url="" Here is the updated code.

 

------------------------------ BEGIN CODE -----------------------------

private delegate void UpdateControlDelegate(LoggingEvent loggingEvent);

 

private void UpdateControl(LoggingEvent loggingEvent)

{

            // do control updating here

            _textBox.AppendText(Layout.Format(loggingEvent));

}

 

protected override void Append (LoggingEvent LoggingEvent)

{

            // prevent exceptions

            if (_textBox != null && _textBox.Created)

            {

                        // make thread safe

                        if (_textBox.InvokeRequired)

                        {

                                    _textBox.Invoke(

                                                new UpdateControlDelegate(UpdateControl),

                                                new object[] {LoggingEvent});

                        }

                        else

                        {

                                    UpdateControl(LoggingEvent);

                        }

            }

}

------------------------------ END CODE -----------------------------

 

thanks again,

Paul

Reply via email to