GSF.Diagnostics.LogEventPublisherInternal.Publish C# (CSharp) Method

Publish() public method

Raises a log message with the provided data.
public Publish ( LogMessageAttributes overriddenAttributes, string message, string details, Exception exception, LogStackMessages initialStackMessage, LogStackTrace initialStackTrace ) : void
overriddenAttributes LogMessageAttributes attributes to use with this message
message string
details string A long text field with the details of the message.
exception System.Exception An exception object if one is provided.
initialStackMessage LogStackMessages
initialStackTrace LogStackTrace
return void
        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);
        }

Usage Example

Ejemplo n.º 1
0
 /// <summary>
 /// Raises a log message with the provided data.
 /// </summary>
 /// <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>
 public void Publish(string message = null, string details = null, Exception exception = null)
 {
     m_internalPublisher.Publish(null, message, details, exception, m_publisher.InitialStackMessages, m_publisher.InitialStackTrace);
 }
LogEventPublisherInternal