GSF.Diagnostics.LogPublisherInternal.HasSubscribers C# (CSharp) Method

HasSubscribers() public method

Checks messages generated by this publisher and the provided attributes will be received by a subscriber.
public HasSubscribers ( LogMessageAttributes attributes ) : bool
attributes LogMessageAttributes
return bool
        public bool HasSubscribers(LogMessageAttributes attributes)
        {
            return !m_logger.RoutingTablesValid || SubscriptionFilterCollection.IsSubscribedTo(attributes);
        }

Usage Example

Ejemplo n.º 1
0
        /// <summary>
        /// Raises a log message with the provided data.
        /// </summary>
        /// <param name="overriddenAttributes">attributes to use with this message</param>
        /// <param name="message"></param>
        /// <param name="details">A long text field with the details of the message.</param>
        /// <param name="exception">An exception object if one is provided.</param>
        /// <param name="initialStackMessage"></param>
        /// <param name="initialStackTrace"></param>
        public void Publish(LogMessageAttributes?overriddenAttributes, string message, string details, Exception exception, LogStackMessages initialStackMessage, LogStackTrace initialStackTrace)
        {
            if (Logger.ShouldSuppressLogMessages)
            {
                return;
            }

            LogMessageAttributes attributes = overriddenAttributes ?? m_attributes;

            if (!m_publisher.HasSubscribers(attributes))
            {
                return;
            }

            if (message == null)
            {
                message = string.Empty;
            }
            if (details == null)
            {
                details = string.Empty;
            }

            var suppressionFlags = m_supressionEngine.IncrementPublishCount();

            if (suppressionFlags != MessageSuppression.None)
            {
                m_messagesSuppressed++;

                if (ShouldRaiseMessageSupressionNotifications && m_suppressionMessageNextPublishTime <= ShortTime.Now)
                {
                    m_suppressionMessageNextPublishTime = ShortTime.Now.AddSeconds(10);
                    MessageSuppressionIndication.Publish($"Message Suppression Is Occurring To: '{ m_owner.TypeData.TypeName }' {m_messagesSuppressed.ToString()} total messages have been suppressed.", m_owner.ToString());
                }

                attributes += suppressionFlags;
                if (!m_publisher.HasSubscribers(attributes))
                {
                    return;
                }
            }

            LogStackMessages currentStackMessages = Logger.GetStackMessages();
            LogStackTrace    currentStackTrace    = LogStackTrace.Empty;

            if (m_stackTraceDepth > 0)
            {
                currentStackTrace = new LogStackTrace(true, 2, m_stackTraceDepth);
            }
            else if (exception != null || attributes.Level >= MessageLevel.Error)
            {
                currentStackTrace = new LogStackTrace(true, 2, 10);
            }

            var logMessage = new LogMessage(m_owner, initialStackMessage, initialStackTrace, currentStackMessages, currentStackTrace, attributes, message, details, exception);

            m_logger.OnNewMessage(logMessage, m_publisher);
        }