public MessageAttributeFilter GetSubscription(LogPublisherInternal publisher) { lock (m_syncRoot) { if (m_allSubscriptions == null) { m_allSubscriptions = new List <SubscriptionInfo>(); } MessageAttributeFilter filter = new MessageAttributeFilter(); foreach (var subscription in m_allSubscriptions) { if (subscription.PublisherFilter.ContainsPublisher(publisher)) { if (subscription.IsIgnoreSubscription) { filter.Remove(subscription.AttributeFilter); } else { filter.Append(subscription.AttributeFilter); } } } return(filter); } }
/// <summary> /// Gets if this subscription contains the publisher. /// </summary> /// <param name="publisher">the publisher to check</param> /// <returns></returns> public bool ContainsPublisher(LogPublisherInternal publisher) { if (publisher == null) { throw new ArgumentNullException(nameof(publisher)); } switch (m_filterType) { case FilterType.Universal: return(true); case FilterType.Assembly: if (m_isExpression) { return(m_regexMatch.IsMatch(publisher.TypeData.AssemblyName)); } return(publisher.TypeData.AssemblyName.Equals(m_text, StringComparison.OrdinalIgnoreCase)); case FilterType.Type: if (m_isExpression) { return(m_regexMatch.IsMatch(publisher.TypeData.TypeName)); } return(publisher.TypeData.TypeName.Equals(m_text, StringComparison.OrdinalIgnoreCase)); default: throw new ArgumentOutOfRangeException(); } }
/// <summary> /// Creates a <see cref="LogEventPublisherInternal"/>. /// </summary> /// <param name="attributes"></param> /// <param name="owner">the owner of the log messages.</param> /// <param name="publisher">the publisher that is used to raise messages</param> /// <param name="logger">the callback for all new messages that are generated.</param> /// <param name="stackTraceDepth"></param> /// <param name="messagesPerSecond"></param> /// <param name="burstLimit"></param> internal LogEventPublisherInternal(LogMessageAttributes attributes, LogEventPublisherDetails owner, LogPublisherInternal publisher, LoggerInternal logger, int stackTraceDepth, double messagesPerSecond, int burstLimit) { if (owner == null) { throw new ArgumentNullException(nameof(owner)); } if (publisher == null) { throw new ArgumentNullException(nameof(publisher)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } m_attributes = attributes; var supression = new LogSuppressionEngine(messagesPerSecond, burstLimit); m_owner = owner; m_logger = logger; m_stackTraceDepth = 0; m_supressionEngine = supression; m_publisher = publisher; m_stackTraceDepth = stackTraceDepth; m_suppressionMessageNextPublishTime = ShortTime.Now; }
/// <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); }
internal LogPublisher(LoggerInternal logger, LogPublisherInternal publisherInstance, MessageClass classification) { m_logger = logger; m_publisherInstance = publisherInstance; m_classification = classification; InitialStackMessages = Logger.GetStackMessages(); InitialStackTrace = new LogStackTrace(true, 1, 10); MaxDistinctEventPublisherCount = 20; m_lookupEventPublishers = new ConcurrentDictionary <Tuple <LogMessageAttributes, string>, LogEventPublisherInternal>(); }
/// <summary> /// Creates a <see cref="LogEventPublisherInternal"/>. /// </summary> /// <param name="attributes"></param> /// <param name="owner">the owner of the log messages.</param> /// <param name="publisher">the publisher that is used to raise messages</param> /// <param name="logger">the callback for all new messages that are generated.</param> /// <param name="stackTraceDepth"></param> /// <param name="messagesPerSecond"></param> /// <param name="burstLimit"></param> internal LogEventPublisherInternal(LogMessageAttributes attributes, LogEventPublisherDetails owner, LogPublisherInternal publisher, LoggerInternal logger, int stackTraceDepth, double messagesPerSecond, int burstLimit) { if (owner == null) throw new ArgumentNullException(nameof(owner)); if (publisher == null) throw new ArgumentNullException(nameof(publisher)); if (logger == null) throw new ArgumentNullException(nameof(logger)); m_attributes = attributes; var supression = new LogSuppressionEngine(messagesPerSecond, burstLimit); m_owner = owner; m_logger = logger; m_stackTraceDepth = 0; m_supressionEngine = supression; m_publisher = publisher; m_stackTraceDepth = stackTraceDepth; m_suppressionMessageNextPublishTime = ShortTime.Now; }
public MessageAttributeFilter GetSubscription(LogPublisherInternal publisher) { lock (m_syncRoot) { if (m_allSubscriptions == null) m_allSubscriptions = new List<SubscriptionInfo>(); MessageAttributeFilter filter = new MessageAttributeFilter(); foreach (var subscription in m_allSubscriptions) { if (subscription.PublisherFilter.ContainsPublisher(publisher)) { if (subscription.IsIgnoreSubscription) { filter.Remove(subscription.AttributeFilter); } else { filter.Append(subscription.AttributeFilter); } } } return filter; } }
/// <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; }
/// <summary> /// Handles the routing of messages through the logging system. /// </summary> /// <param name="message">the message to route</param> /// <param name="publisher">the publisher that is originating this message.</param> public void OnNewMessage(LogMessage message, LogPublisherInternal publisher) { m_messages.Enqueue(Tuple.Create(message, publisher)); m_routingTask.Start(50); //Allow a 50ms delay for multiple logs to queue if in a burst period. }
/// <summary> /// This method should be called with a lock on m_syncRoot /// </summary> private void CalculateRoutingTableForPublisherSync(List<LogSubscriberInternal> subscribers, LogPublisherInternal publisher) { MessageAttributeFilterCollection filterCollection = new MessageAttributeFilterCollection(); foreach (var sub in subscribers) { filterCollection.Add(sub.GetSubscription(publisher), sub); } publisher.SubscriptionFilterCollection = filterCollection; }
internal LogPublisher(LoggerInternal logger, LogPublisherInternal publisherInstance, MessageClass classification) { m_logger = logger; m_publisherInstance = publisherInstance; m_classification = classification; InitialStackMessages = Logger.GetStackMessages(); InitialStackTrace = new LogStackTrace(true, 1, 10); MaxDistinctEventPublisherCount = 20; m_lookupEventPublishers = new ConcurrentDictionary<Tuple<LogMessageAttributes, string>, LogEventPublisherInternal>(); }
/// <summary> /// Gets if this subscription contains the publisher. /// </summary> /// <param name="publisher">the publisher to check</param> /// <returns></returns> public bool ContainsPublisher(LogPublisherInternal publisher) { if (publisher == null) throw new ArgumentNullException(nameof(publisher)); switch (m_filterType) { case FilterType.Universal: return true; case FilterType.Assembly: if (m_isExpression) return m_regexMatch.IsMatch(publisher.TypeData.AssemblyName); return publisher.TypeData.AssemblyName.Equals(m_text, StringComparison.OrdinalIgnoreCase); case FilterType.Type: if (m_isExpression) return m_regexMatch.IsMatch(publisher.TypeData.TypeName); return publisher.TypeData.TypeName.Equals(m_text, StringComparison.OrdinalIgnoreCase); default: throw new ArgumentOutOfRangeException(); } }
/// <summary> /// Handles the routing of messages through the logging system. /// </summary> /// <param name="message">the message to route</param> /// <param name="publisher">the publisher that is originating this message.</param> public void OnNewMessage(LogMessage message, LogPublisherInternal publisher) { m_messages.Enqueue(Tuple.Create(message, publisher)); m_routingTask.Start(50); //Allow a 50ms delay for multiple logs to queue if in a burst period. }
/// <summary> /// This method should be called with a lock on m_syncRoot /// </summary> private void CalculateRoutingTableForPublisherSync(List <LogSubscriberInternal> subscribers, LogPublisherInternal publisher) { MessageAttributeFilterCollection filterCollection = new MessageAttributeFilterCollection(); foreach (var sub in subscribers) { filterCollection.Add(sub.GetSubscription(publisher), sub); } publisher.SubscriptionFilterCollection = filterCollection; }