A LogSubscriberInternal that collects logs
コード例 #1
0
ファイル: LoggerInternal.cs プロジェクト: xj0229/gsf
        /// <summary>
        /// Recalculates the entire routing table on a separate thread.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CalculateRoutingTable(object sender, EventArgs <ScheduledTaskRunningReason> e)
        {
            lock (m_syncRoot)
            {
                //Some other thread won on the race condition.
                if (RoutingTablesValid)
                {
                    return;
                }

                var subscribers = new List <LogSubscriberInternal>(m_subscribers.Count);
                m_subscribers.RemoveWhere(x =>
                {
                    LogSubscriberInternal subscriber = (LogSubscriberInternal)x.Target;
                    if (subscriber != null)
                    {
                        subscribers.Add(subscriber);
                        return(false);
                    }
                    return(true);
                });

                foreach (var pub in m_allPublishers)
                {
                    CalculateRoutingTableForPublisherSync(subscribers, pub);
                }
                RoutingTablesValid = true;
            }
        }
コード例 #2
0
ファイル: LoggerInternal.cs プロジェクト: xj0229/gsf
        /// <summary>
        /// Creates a type topic on a specified type.
        /// </summary>
        /// <param name="type">the type to create the topic from</param>
        /// <returns></returns>
        public LogPublisherInternal CreateType(Type type)
        {
            if ((object)type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            LogPublisherInternal publisher;

            lock (m_syncRoot)
            {
                if (!m_typeIndexCache.TryGetValue(type, out publisher))
                {
                    publisher = new LogPublisherInternal(this, type);
                    m_typeIndexCache.Add(type, publisher);
                    if (!m_disposing)
                    {
                        m_allPublishers.Add(publisher);
                        var lst = new List <LogSubscriberInternal>();
                        foreach (var logSubscriberInternal in m_subscribers)
                        {
                            LogSubscriberInternal target = logSubscriberInternal.Target as LogSubscriberInternal;
                            if (target != null)
                            {
                                lst.Add(target);
                            }
                        }
                        CalculateRoutingTableForPublisherSync(lst, publisher);
                    }
                }
            }
            return(publisher);
        }
コード例 #3
0
ファイル: LoggerInternal.cs プロジェクト: xj0229/gsf
 /// <summary>
 /// Creates a <see cref="LogSubscriber"/> that can subscribe to log messages.
 /// </summary>
 /// <returns></returns>
 public LogSubscriberInternal CreateSubscriber()
 {
     lock (m_syncRoot)
     {
         if (m_disposing)
         {
             return(LogSubscriberInternal.DisposedSubscriber);
         }
         var s = new LogSubscriberInternal(RecalculateRoutingTable);
         m_subscribers.Add(s.Reference);
         return(s);
     }
 }
コード例 #4
0
 public void Add(MessageAttributeFilter filter, LogSubscriberInternal subscriber)
 {
     Routes.Add(Tuple.Create(filter, subscriber.Reference));
     Append(filter);
 }
コード例 #5
0
 /// <summary>
 /// Creates a <see cref="LogSubscriber"/>
 /// </summary>
 internal LogSubscriber(LogSubscriberInternal subscriber)
 {
     m_subscriber = subscriber;
 }
コード例 #6
0
 static LogSubscriberInternal()
 {
     DisposedSubscriber = new LogSubscriberInternal(null);
     DisposedSubscriber.Dispose();
 }
コード例 #7
0
ファイル: LogSubscriberInternal.cs プロジェクト: xj0229/gsf
 static LogSubscriberInternal()
 {
     DisposedSubscriber = new LogSubscriberInternal(null);
     DisposedSubscriber.Dispose();
 }
コード例 #8
0
 public void Add(MessageAttributeFilter filter, LogSubscriberInternal subscriber)
 {
     Routes.Add(Tuple.Create(filter, subscriber.Reference));
     Append(filter);
 }
コード例 #9
0
 /// <summary>
 /// Creates a <see cref="LogSubscriber"/> that can subscribe to log messages.
 /// </summary>
 /// <returns></returns>
 public LogSubscriberInternal CreateSubscriber()
 {
     lock (m_syncRoot)
     {
         if (m_disposing)
             return LogSubscriberInternal.DisposedSubscriber;
         var s = new LogSubscriberInternal(RecalculateRoutingTable);
         m_subscribers.Add(s.Reference);
         return s;
     }
 }
コード例 #10
0
 /// <summary>
 /// Creates a <see cref="LogSubscriber"/>
 /// </summary>
 internal LogSubscriber(LogSubscriberInternal subscriber)
 {
     m_subscriber = subscriber;
 }