0

I'm having difficulties trying to understand the configurations for log4net formName and textBoxName elements. I have been following an earlier question here

specifically I am trying to create a custom user control containing a textbox to act as the logger

namespace foo {
    public partial class LoggingControl : UserControl, IAppender {
        private ILog _logger = LogManager.GetLogger(typeof(LoggingControl));

        public LoggingControl() {
            InitializeComponent();
        }

        public ILog Logger {
            get {
                return _logger;
            }
        }

        public string FormName {
            get;
            set;
        }

        public string TextBoxName {
            get;
           set;
        }

        public void DoAppend(log4net.Core.LoggingEvent loggingEvent) {
            textBox.AppendText(loggingEvent.MessageObject.ToString() + Environment.NewLine);
        }

        public void Close() {
        }
    }
}

in my config I have

<log4net>
    <appender name="Logger" type="foo.LoggingControl">
        <formName value="MainForm"/>    --- ###01
        <textBoxName value="textBox"/>  --- ###02
        <root>
            <level value="DEBUG">
                <appender-ref ref="textbox">
                </appender-ref>
            </level>
         </root>
    </appender>
</log4net>
  1. is set to the name of the form that contains the custom control which contains the logging textbox
  2. is set to the name of the textbox inside the custom control.

This isn't working, what am I missing?

Community
  • 1
  • 1
mfc
  • 3,018
  • 5
  • 31
  • 43
  • Please try to use AppenderSkeleton and in config make formName and textBoxName case sensitive. Hope this help you. – dotnetstep Oct 27 '14 at 03:25
  • hi Anik, i don't see an AppenderSkeleton, using latest 1.2.13-bin-newkey. – mfc Oct 27 '14 at 03:32

2 Answers2

2

When using a SkeletonAppender you only have to find a way to find the textbox:

public class TextBoxAppender : AppenderSkeleton
{
    protected override void Append(LoggingEvent loggingEvent)
    {
         TextBox tb = FindMyTextBox();
         tb.Text += RenderLoggingEvent(loggingEvent);
    }

    private TextBox FindMyTextBox(){
        //Get the textbox from your program and return it for logging
    }
}

An other option can be to expose a static logging text with property changed events and bind it to your textbox its text.

Peter
  • 27,590
  • 8
  • 64
  • 84
0

You should use textBox.BeginInvoke instead of textBox.Invoke for threadsafe.

toha
  • 5,095
  • 4
  • 40
  • 52
zony
  • 1
  • 1