Publish() public méthode

Raises a log message with the provided data.
public Publish ( MessageFlags flags, string message = null, string details = null, Exception exception = null ) : void
flags MessageFlags additional flags to set to this log
message string
details string A long text field with the details of the message.
exception System.Exception An exception object if one is provided.
Résultat void
Exemple #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);
        }
Exemple #2
0
            private void task_Running(object sender, EventArgs <ScheduledTaskRunningReason> e)
            {
                ShortTime currentTime = ShortTime.Now;
                ShortTime queueTime;

                lock (this)
                {
                    if (!m_time.HasValue)
                    {
                        return; //Should never happen, but just in case;
                    }
                    queueTime = m_time.Value;
                    m_time    = null;
                }

                double delay = (currentTime - queueTime).TotalMilliseconds;

                if (delay > m_delay + 1000)
                {
                    m_logLarge.Publish(delay.ToString() + " ms");
                }
                else if (delay > m_delay + 500)
                {
                    m_logMedium.Publish(delay.ToString() + " ms");
                }
                else if (delay > m_delay + 100)
                {
                    m_logSmall.Publish(delay.ToString() + " ms");
                }
                else
                {
                    return;
                }

                //If I published a message, a long delay could have occurred and messed
                //up my timer, therefore reset the current time.
                lock (this)
                {
                    if (m_time.HasValue)
                    {
                        m_time = ShortTime.Now;
                    }
                }
            }