If you want to show the log4net logging direct in your application by using a textbox, you can use the following link:

http://weblogs.asp.net/psteele/archive/2010/01/25/live-capture-of-log4net-logging.aspx

I tried it and it works great:

 

using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; using log4net.Appender; using System.Threading; namespace Rvl.Demo.WindowsFormsApplication.UserControls { public partial class SettingsUserControl : UserControl, IAppender {

        private static ILog _logger = LogManager.GetLogger(typeof(SettingsUserControl));
        /// <summary>
        /// This logger property is used to log events
        /// </summary>
        public static ILog Logger
        {
            get { return _logger; }
        }

/// <summary>
///
Constructor
/// </summary>
public SettingsUserControl()
{
InitializeComponent();
}
/// <summary>
///
Show progress in outputTextBox
/// </summary>
/// <param name="loggingEvent"></param>
public void DoAppend(log4net.Core.LoggingEvent loggingEvent)
{
outPutTextBox.AppendText(loggingEvent.MessageObject.ToString() + Environment.NewLine);
}
/// <summary>
///
Close the log4net appender
/// </summary>
public void Close()
{
//throw new NotImplementedException();
}
/// <summary>
///
Configure the databases
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ConfigureDatabasesButton_Click(object sender, EventArgs e)
{
try
{
Cursor = Cursors.WaitCursor;

outPutTextBox.Clear();
outPutTextBox.AppendText("Start configuration of the databases" + Environment.NewLine);
Logger.Debug("Sp 1 execute...");
Thread.Sleep(2000);
Logger.Debug("Sp 2 execute...");
Thread.Sleep(2000);
Logger.Debug("Sp 3 execute...");
Thread.Sleep(2000);
Logger.Debug("Sp 4 execute...");
Thread.Sleep(2000);
Logger.Debug("Finished");
}
finally
{
Cursor = Cursors.Default;
}
}
}
}

 

Result

clip_image002

4 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.