logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From BlackMatrix <primusla...@web.de>
Subject ListViewAppender: ListView always null?
Date Sat, 03 Nov 2012 13:08:48 GMT

Hi.

Ich have written a ListViewAppender to bind my log messages to a WPF
listview control.

Always when I write a log message my application jumps to the 

        protected override void Append(LoggingEvent LoggingEvent)

method of my ListViewAppender, but the _listView is after initialization
always null.

 public partial class MainWindow : Window
    {
        private static readonly ILog log =
LogManager.GetLogger(typeof(MainWindow));

        public MainWindow()
        {
            InitializeComponent();

            ListViewAppender listViewAppender = new
ListViewAppender(listView);

            log.Error("Error.");
        }
    }

    public class ListViewAppender : AppenderSkeleton
    {
        private ListView _listView;

        public ListViewAppender()
            : base()
        {

        }

        public ListViewAppender(ListView listview)
            : base()
        {
            _listView = listview;
        }

        private delegate void UpdateControlDelegate(LoggingEvent
loggingEvent);

        private void UpdateControl(LoggingEvent loggingEvent)
        {
           // ...
        }

        protected override void Append(LoggingEvent LoggingEvent)
        {
            if (!_listView.Dispatcher.CheckAccess())// !!! _listView == null
                _listView.Dispatcher.Invoke(new
UpdateControlDelegate(UpdateControl), new object[] { LoggingEvent });
            else
                UpdateControl(LoggingEvent);
        }

XML-Code:
<log4net debug="true">
  <appender name="ListViewAppender" type="WpfApplication2.ListViewAppender">
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date [%thread] %-5level %logger
[%property{NDC}] - %message%newline" />
    </layout>
  </appender>

  <root>
    <level value="ALL"/>
    <appender-ref ref="ListViewAppender" />
  </root>
</log4net>

C#-Code:
   
-- 
View this message in context: http://old.nabble.com/ListViewAppender%3A-ListView-always-null--tp34636403p34636403.html
Sent from the Log4net - Users mailing list archive at Nabble.com.


Mime
View raw message