All of the attributes that can be assigned to a LogMessage.
Пример #1
0
        /// <summary>
        /// Initializes an <see cref="LogEventPublisher"/> with the provided values.
        /// </summary>
        /// <param name="level">the level of the message</param>
        /// <param name="flags">associated flags</param>
        /// <param name="eventName"></param>
        /// <param name="stackTraceDepth"></param>
        /// <param name="messagesPerSecond"></param>
        /// <param name="burstLimit"></param>
        /// <returns></returns>
        public LogEventPublisher RegisterEvent(MessageLevel level, MessageFlags flags, string eventName, int stackTraceDepth, MessageRate messagesPerSecond, int burstLimit)
        {
            LogMessageAttributes      flag      = new LogMessageAttributes(m_classification, level, MessageSuppression.None, flags);
            LogEventPublisherInternal publisher = InternalRegisterEvent(flag, eventName, stackTraceDepth, messagesPerSecond, burstLimit);

            return(new LogEventPublisher(this, publisher));
        }
Пример #2
0
        /// <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;
        }
Пример #3
0
        /// <summary>
        /// Initializes an <see cref="LogEventPublisher"/> with the provided values.
        /// </summary>
        /// <param name="level">the level of the message</param>
        /// <param name="flags">associated flags</param>
        /// <param name="eventName">the name of the event.</param>
        /// <returns></returns>
        public LogEventPublisher RegisterEvent(MessageLevel level, MessageFlags flags, string eventName)
        {
            LogMessageAttributes      flag      = new LogMessageAttributes(m_classification, level, MessageSuppression.None, flags);
            LogEventPublisherInternal publisher = InternalRegisterEvent(flag, eventName);

            return(new LogEventPublisher(this, publisher));
        }
Пример #4
0
        /// <summary>
        /// Creates a log message
        /// </summary>
        internal LogMessage(LogEventPublisherDetails eventPublisherDetails, LogStackMessages initialStackMessages, LogStackTrace initialStackTrace, LogStackMessages currentStackMessages, LogStackTrace currentStackTrace, LogMessageAttributes flags, string message, string details, Exception exception)
        {
            if (eventPublisherDetails == null)
            {
                throw new ArgumentNullException(nameof(eventPublisherDetails));
            }

            if (exception != null)
            {
                ExceptionString = exception.ToString();
            }
            else
            {
                ExceptionString = string.Empty;
            }

            EventPublisherDetails = eventPublisherDetails;
            InitialStackMessages  = initialStackMessages ?? LogStackMessages.Empty;
            InitialStackTrace     = initialStackTrace ?? LogStackTrace.Empty;
            CurrentStackMessages  = currentStackMessages ?? LogStackMessages.Empty;
            CurrentStackTrace     = currentStackTrace ?? LogStackTrace.Empty;
            UtcTime = DateTime.UtcNow;
            LogMessageAttributes = flags;
            Message         = message ?? string.Empty;
            Details         = details ?? string.Empty;
            Exception       = exception;
            ManagedThreadID = Thread.CurrentThread.ManagedThreadId;
            PreviousFirstChanceExceptionSequenceNumber = Logger.PreviousFirstChanceExceptionSequenceNumber;
        }
Пример #5
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);
        }
Пример #6
0
        /// <summary>
        /// Initializes an <see cref="LogEventPublisher"/> with a series of settings.
        /// </summary>
        /// <param name="attributes"></param>
        /// <param name="eventName"></param>
        /// <param name="stackTraceDepth"></param>
        /// <param name="messagesPerSecond"></param>
        /// <param name="burstLimit"></param>
        /// <returns></returns>
        private LogEventPublisherInternal InternalRegisterEvent(LogMessageAttributes attributes, string eventName, int stackTraceDepth, MessageRate messagesPerSecond, int burstLimit)
        {
            if (eventName == null)
            {
                eventName = string.Empty;
            }
            LogEventPublisherInternal publisher;

            if (m_lookupEventPublishers.TryGetValue(Tuple.Create(attributes, eventName), out publisher))
            {
                return(publisher);
            }
            return(InternalRegisterNewEvent(attributes, eventName, stackTraceDepth, messagesPerSecond, burstLimit));
        }
Пример #7
0
        /// <summary>
        /// Gets if this subscription includes the provided message.
        /// </summary>
        /// <returns></returns>
        public bool IsSubscribedTo(LogMessageAttributes flags)
        {
            switch (flags.Classification)
            {
            case MessageClass.Component:
                if (flags.MessageSuppression != MessageSuppression.None)
                {
                    if ((1 << ((int)flags.MessageSuppression - 1) & (int)m_componentMessageSuppression) == 0)
                    {
                        return(false);
                    }
                }
                if (flags.Level == MessageLevel.NA)
                {
                    return((flags.Flags & m_componentFlags) != 0);
                }
                return(((1 << ((int)flags.Level - 1)) & (int)m_componentLevel) != 0 || (flags.Flags & m_componentFlags) != 0);

            case MessageClass.Framework:
                if (flags.MessageSuppression != MessageSuppression.None)
                {
                    if ((1 << ((int)flags.MessageSuppression - 1) & (int)m_frameworkMessageSuppression) == 0)
                    {
                        return(false);
                    }
                }
                if (flags.Level == MessageLevel.NA)
                {
                    return((flags.Flags & m_frameworkFlags) != 0);
                }
                return(((1 << ((int)flags.Level - 1)) & (int)m_frameworkLevel) != 0 || (flags.Flags & m_frameworkFlags) != 0);

            case MessageClass.Application:
                if (flags.MessageSuppression != MessageSuppression.None)
                {
                    if ((1 << ((int)flags.MessageSuppression - 1) & (int)m_applicationMessageSuppression) == 0)
                    {
                        return(false);
                    }
                }
                if (flags.Level == MessageLevel.NA)
                {
                    return((flags.Flags & m_applicationFlags) != 0);
                }
                return(((1 << ((int)flags.Level - 1)) & (int)m_applicationLevel) != 0 || (flags.Flags & m_applicationFlags) != 0);

            default:
                return(false);
            }
        }
        /// <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;
        }
Пример #9
0
        private LogEventPublisherInternal InternalRegisterNewEvent(LogMessageAttributes attributes, string eventName, int stackTraceDepth, double messagesPerSecond, int burstLimit)
        {
            //Note: A race condition can cause more then the maximum number of entries to exist, however, this is not a concern.
            if (m_lookupEventPublishers.Count > MaxDistinctEventPublisherCount)
            {
                if (m_excessivePublisherEventNames == null)
                {
                    var owner1 = new LogEventPublisherDetails(m_publisherInstance.TypeData,
                                                              "Excessive Event Names: Event names for this publisher has been limited to " + MaxDistinctEventPublisherCount.ToString() +
                                                              "Please adjust MaxDistinctEventPublisherCount if this is not a bug and this publisher can truly create this many publishers.");
                    m_excessivePublisherEventNames = new LogEventPublisherInternal(attributes, owner1, m_publisherInstance, m_logger, stackTraceDepth, messagesPerSecond, burstLimit);
                }
                return(m_excessivePublisherEventNames);
            }

            LogEventPublisherInternal publisher;
            var owner = new LogEventPublisherDetails(m_publisherInstance.TypeData, eventName);

            publisher = new LogEventPublisherInternal(attributes, owner, m_publisherInstance, m_logger, stackTraceDepth, messagesPerSecond, burstLimit);
            publisher = m_lookupEventPublishers.GetOrAdd(Tuple.Create(attributes, eventName), publisher);
            return(publisher);
        }
Пример #10
0
        /// <summary>
        /// Initializes an <see cref="LogEventPublisher"/> with a series of settings.
        /// </summary>
        /// <param name="attributes"></param>
        /// <param name="eventName">the name of the event.</param>
        /// <returns></returns>
        private LogEventPublisherInternal InternalRegisterEvent(LogMessageAttributes attributes, string eventName)
        {
            if (eventName == null)
            {
                eventName = string.Empty;
            }
            LogEventPublisherInternal publisher;

            if (m_lookupEventPublishers.TryGetValue(Tuple.Create(attributes, eventName), out publisher))
            {
                return(publisher);
            }

            //If messages events are unclassified allow a higher message throughput rate.
            double messagesPerSecond = 1;
            int    burstRate         = 20;

            if (eventName.Length == 0)
            {
                messagesPerSecond = 5;
                burstRate         = 100;
            }
            return(InternalRegisterNewEvent(attributes, eventName, 0, messagesPerSecond, burstRate));
        }
Пример #11
0
        /// <summary>
        /// Creates a log message
        /// </summary>
        internal LogMessage(LogEventPublisherDetails eventPublisherDetails, LogStackMessages initialStackMessages, LogStackTrace initialStackTrace, LogStackMessages currentStackMessages, LogStackTrace currentStackTrace, LogMessageAttributes flags, string message, string details, Exception exception)
        {
            if (eventPublisherDetails == null)
                throw new ArgumentNullException(nameof(eventPublisherDetails));

            if (exception != null)
            {
                ExceptionString = exception.ToString();
            }
            else
            {
                ExceptionString = string.Empty;
            }

            EventPublisherDetails = eventPublisherDetails;
            InitialStackMessages = initialStackMessages ?? LogStackMessages.Empty;
            InitialStackTrace = initialStackTrace ?? LogStackTrace.Empty;
            CurrentStackMessages = currentStackMessages ?? LogStackMessages.Empty;
            CurrentStackTrace = currentStackTrace ?? LogStackTrace.Empty;
            UtcTime = DateTime.UtcNow;
            LogMessageAttributes = flags;
            Message = message ?? string.Empty;
            Details = details ?? string.Empty;
            Exception = exception;
            ManagedThreadID = Thread.CurrentThread.ManagedThreadId;
            PreviousFirstChanceExceptionSequenceNumber = Logger.PreviousFirstChanceExceptionSequenceNumber;
        }
Пример #12
0
        /// <summary>
        /// Loads a log messages from the supplied stream
        /// </summary>
        /// <param name="stream">the stream to load the log message from.</param>
        /// <param name="saveHelper">A save helper that will condense objects</param>
        internal LogMessage(Stream stream, LogMessageSaveHelper saveHelper = null)
        {
            if (saveHelper == null)
                saveHelper = LogMessageSaveHelper.Create(true);

            byte version = stream.ReadNextByte();
            switch (version)
            {
                case 1:
                    EventPublisherDetails = saveHelper.LoadEventPublisherDetails(stream);
                    InitialStackMessages = saveHelper.LoadStackMessages(stream);
                    InitialStackTrace = saveHelper.LoadStackTrace(stream);
                    CurrentStackMessages = saveHelper.LoadStackMessages(stream);
                    CurrentStackTrace = saveHelper.LoadStackTrace(stream);
                    UtcTime = stream.ReadDateTime();
                    LogMessageAttributes = new LogMessageAttributes(stream);
                    Message = stream.ReadString();
                    Details = stream.ReadString();
                    Exception = null;
                    ExceptionString = stream.ReadString();
                    ManagedThreadID = -1;
                    PreviousFirstChanceExceptionSequenceNumber = -1;
                    break;
                case 2:
                    EventPublisherDetails = saveHelper.LoadEventPublisherDetails(stream);
                    InitialStackMessages = saveHelper.LoadStackMessages(stream);
                    InitialStackTrace = saveHelper.LoadStackTrace(stream);
                    CurrentStackMessages = saveHelper.LoadStackMessages(stream);
                    CurrentStackTrace = saveHelper.LoadStackTrace(stream);
                    UtcTime = stream.ReadDateTime();
                    LogMessageAttributes = new LogMessageAttributes(stream);
                    Message = stream.ReadString();
                    Details = stream.ReadString();
                    Exception = null;
                    ExceptionString = stream.ReadString();
                    ManagedThreadID = stream.ReadInt32();
                    PreviousFirstChanceExceptionSequenceNumber = -1;
                    break;
                case 3:
                    EventPublisherDetails = saveHelper.LoadEventPublisherDetails(stream);
                    InitialStackMessages = saveHelper.LoadStackMessages(stream);
                    InitialStackTrace = saveHelper.LoadStackTrace(stream);
                    CurrentStackMessages = saveHelper.LoadStackMessages(stream);
                    CurrentStackTrace = saveHelper.LoadStackTrace(stream);
                    UtcTime = stream.ReadDateTime();
                    LogMessageAttributes = new LogMessageAttributes(stream);
                    Message = saveHelper.LoadString(stream);
                    Details = saveHelper.LoadString(stream);
                    Exception = null;
                    ExceptionString = saveHelper.LoadString(stream);
                    ManagedThreadID = stream.ReadInt32();
                    PreviousFirstChanceExceptionSequenceNumber = -1;
                    break;
                case 4:
                    EventPublisherDetails = saveHelper.LoadEventPublisherDetails(stream);
                    InitialStackMessages = saveHelper.LoadStackMessages(stream);
                    InitialStackTrace = saveHelper.LoadStackTrace(stream);
                    CurrentStackMessages = saveHelper.LoadStackMessages(stream);
                    CurrentStackTrace = saveHelper.LoadStackTrace(stream);
                    UtcTime = stream.ReadDateTime();
                    LogMessageAttributes = new LogMessageAttributes(stream);
                    Message = saveHelper.LoadString(stream);
                    Details = saveHelper.LoadString(stream);
                    Exception = null;
                    ExceptionString = saveHelper.LoadString(stream);
                    ManagedThreadID = stream.ReadInt32();
                    PreviousFirstChanceExceptionSequenceNumber = stream.ReadInt32();
                    break;
                default:
                    throw new VersionNotFoundException();
            }
        }
 /// <summary>
 /// Checks messages generated by this publisher and the provided attributes will be received by a subscriber.
 /// </summary>
 /// <param name="attributes"></param>
 /// <returns></returns>
 public bool HasSubscribers(LogMessageAttributes attributes)
 {
     return !m_logger.RoutingTablesValid || SubscriptionFilterCollection.IsSubscribedTo(attributes);
 }
Пример #14
0
        private LogEventPublisherInternal InternalRegisterNewEvent(LogMessageAttributes attributes, string eventName, int stackTraceDepth, double messagesPerSecond, int burstLimit)
        {
            //Note: A race condition can cause more then the maximum number of entries to exist, however, this is not a concern.
            if (m_lookupEventPublishers.Count > MaxDistinctEventPublisherCount)
            {
                if (m_excessivePublisherEventNames == null)
                {
                    var owner1 = new LogEventPublisherDetails(m_publisherInstance.TypeData,
                        "Excessive Event Names: Event names for this publisher has been limited to " + MaxDistinctEventPublisherCount.ToString() +
                        "Please adjust MaxDistinctEventPublisherCount if this is not a bug and this publisher can truly create this many publishers.");
                    m_excessivePublisherEventNames = new LogEventPublisherInternal(attributes, owner1, m_publisherInstance, m_logger, stackTraceDepth, messagesPerSecond, burstLimit);
                }
                return m_excessivePublisherEventNames;
            }

            LogEventPublisherInternal publisher;
            var owner = new LogEventPublisherDetails(m_publisherInstance.TypeData, eventName);
            publisher = new LogEventPublisherInternal(attributes, owner, m_publisherInstance, m_logger, stackTraceDepth, messagesPerSecond, burstLimit);
            publisher = m_lookupEventPublishers.GetOrAdd(Tuple.Create(attributes, eventName), publisher);
            return publisher;
        }
Пример #15
0
 /// <summary>
 /// Initializes an <see cref="LogEventPublisher"/> with a series of settings.
 /// </summary>
 /// <param name="attributes"></param>
 /// <param name="eventName"></param>
 /// <param name="stackTraceDepth"></param>
 /// <param name="messagesPerSecond"></param>
 /// <param name="burstLimit"></param>
 /// <returns></returns>
 private LogEventPublisherInternal InternalRegisterEvent(LogMessageAttributes attributes, string eventName, int stackTraceDepth, MessageRate messagesPerSecond, int burstLimit)
 {
     if (eventName == null)
         eventName = string.Empty;
     LogEventPublisherInternal publisher;
     if (m_lookupEventPublishers.TryGetValue(Tuple.Create(attributes, eventName), out publisher))
     {
         return publisher;
     }
     return InternalRegisterNewEvent(attributes, eventName, stackTraceDepth, messagesPerSecond, burstLimit);
 }
Пример #16
0
 /// <summary>
 /// Raises a log message with the provided data.
 /// </summary>
 /// <param name="level">the level of the message</param>
 /// <param name="flags">associated flags</param>
 /// <param name="eventName">A short name about what this message is detailing. Typically this will be a few words.</param>
 /// <param name="message"> A longer message than <see param="eventName"/> giving more specifics about the actual message. 
 /// Typically, this will be up to 1 line of text.</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(MessageLevel level, MessageFlags flags, string eventName, string message = null, string details = null, Exception exception = null)
 {
     LogMessageAttributes flag = new LogMessageAttributes(m_classification, level, MessageSuppression.None, flags);
     InternalRegisterEvent(flag, eventName).Publish(null, message, details, exception, InitialStackMessages, InitialStackTrace);
 }
Пример #17
0
 /// <summary>
 /// Initializes an <see cref="LogEventPublisher"/> with the provided values.
 /// </summary>
 /// <param name="level">the level of the message</param>
 /// <param name="flags">associated flags</param>
 /// <param name="eventName"></param>
 /// <param name="stackTraceDepth"></param>
 /// <param name="messagesPerSecond"></param>
 /// <param name="burstLimit"></param>
 /// <returns></returns>
 public LogEventPublisher RegisterEvent(MessageLevel level, MessageFlags flags, string eventName, int stackTraceDepth, MessageRate messagesPerSecond, int burstLimit)
 {
     LogMessageAttributes flag = new LogMessageAttributes(m_classification, level, MessageSuppression.None, flags);
     LogEventPublisherInternal publisher = InternalRegisterEvent(flag, eventName, stackTraceDepth, messagesPerSecond, burstLimit);
     return new LogEventPublisher(this, publisher);
 }
Пример #18
0
        /// <summary>
        /// Raises a log message with the provided data.
        /// </summary>
        /// <param name="level">the level of the message</param>
        /// <param name="flags">associated flags</param>
        /// <param name="eventName">A short name about what this message is detailing. Typically this will be a few words.</param>
        /// <param name="message"> A longer message than <see param="eventName"/> giving more specifics about the actual message.
        /// Typically, this will be up to 1 line of text.</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(MessageLevel level, MessageFlags flags, string eventName, string message = null, string details = null, Exception exception = null)
        {
            LogMessageAttributes flag = new LogMessageAttributes(m_classification, level, MessageSuppression.None, flags);

            InternalRegisterEvent(flag, eventName).Publish(null, message, details, exception, InitialStackMessages, InitialStackTrace);
        }
        /// <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);
        }
Пример #20
0
 /// <summary>
 /// Checks messages generated by this publisher and the provided attributes will be received by a subscriber.
 /// </summary>
 /// <param name="attributes"></param>
 /// <returns></returns>
 public bool HasSubscribers(LogMessageAttributes attributes)
 {
     return(!m_logger.RoutingTablesValid || SubscriptionFilterCollection.IsSubscribedTo(attributes));
 }
Пример #21
0
        /// <summary>
        /// Loads a log messages from the supplied stream
        /// </summary>
        /// <param name="stream">the stream to load the log message from.</param>
        /// <param name="saveHelper">A save helper that will condense objects</param>
        internal LogMessage(Stream stream, LogMessageSaveHelper saveHelper = null)
        {
            if (saveHelper == null)
            {
                saveHelper = LogMessageSaveHelper.Create(true);
            }

            byte version = stream.ReadNextByte();

            switch (version)
            {
            case 1:
                EventPublisherDetails = saveHelper.LoadEventPublisherDetails(stream);
                InitialStackMessages  = saveHelper.LoadStackMessages(stream);
                InitialStackTrace     = saveHelper.LoadStackTrace(stream);
                CurrentStackMessages  = saveHelper.LoadStackMessages(stream);
                CurrentStackTrace     = saveHelper.LoadStackTrace(stream);
                UtcTime = stream.ReadDateTime();
                LogMessageAttributes = new LogMessageAttributes(stream);
                Message         = stream.ReadString();
                Details         = stream.ReadString();
                Exception       = null;
                ExceptionString = stream.ReadString();
                ManagedThreadID = -1;
                PreviousFirstChanceExceptionSequenceNumber = -1;
                break;

            case 2:
                EventPublisherDetails = saveHelper.LoadEventPublisherDetails(stream);
                InitialStackMessages  = saveHelper.LoadStackMessages(stream);
                InitialStackTrace     = saveHelper.LoadStackTrace(stream);
                CurrentStackMessages  = saveHelper.LoadStackMessages(stream);
                CurrentStackTrace     = saveHelper.LoadStackTrace(stream);
                UtcTime = stream.ReadDateTime();
                LogMessageAttributes = new LogMessageAttributes(stream);
                Message         = stream.ReadString();
                Details         = stream.ReadString();
                Exception       = null;
                ExceptionString = stream.ReadString();
                ManagedThreadID = stream.ReadInt32();
                PreviousFirstChanceExceptionSequenceNumber = -1;
                break;

            case 3:
                EventPublisherDetails = saveHelper.LoadEventPublisherDetails(stream);
                InitialStackMessages  = saveHelper.LoadStackMessages(stream);
                InitialStackTrace     = saveHelper.LoadStackTrace(stream);
                CurrentStackMessages  = saveHelper.LoadStackMessages(stream);
                CurrentStackTrace     = saveHelper.LoadStackTrace(stream);
                UtcTime = stream.ReadDateTime();
                LogMessageAttributes = new LogMessageAttributes(stream);
                Message         = saveHelper.LoadString(stream);
                Details         = saveHelper.LoadString(stream);
                Exception       = null;
                ExceptionString = saveHelper.LoadString(stream);
                ManagedThreadID = stream.ReadInt32();
                PreviousFirstChanceExceptionSequenceNumber = -1;
                break;

            case 4:
                EventPublisherDetails = saveHelper.LoadEventPublisherDetails(stream);
                InitialStackMessages  = saveHelper.LoadStackMessages(stream);
                InitialStackTrace     = saveHelper.LoadStackTrace(stream);
                CurrentStackMessages  = saveHelper.LoadStackMessages(stream);
                CurrentStackTrace     = saveHelper.LoadStackTrace(stream);
                UtcTime = stream.ReadDateTime();
                LogMessageAttributes = new LogMessageAttributes(stream);
                Message         = saveHelper.LoadString(stream);
                Details         = saveHelper.LoadString(stream);
                Exception       = null;
                ExceptionString = saveHelper.LoadString(stream);
                ManagedThreadID = stream.ReadInt32();
                PreviousFirstChanceExceptionSequenceNumber = stream.ReadInt32();
                break;

            default:
                throw new VersionNotFoundException();
            }
        }
Пример #22
0
 /// <summary>
 /// Initializes an <see cref="LogEventPublisher"/> with the provided values.
 /// </summary>
 /// <param name="level">the level of the message</param>
 /// <param name="flags">associated flags</param>
 /// <param name="eventName">the name of the event.</param>
 /// <returns></returns>
 public LogEventPublisher RegisterEvent(MessageLevel level, MessageFlags flags, string eventName)
 {
     LogMessageAttributes flag = new LogMessageAttributes(m_classification, level, MessageSuppression.None, flags);
     LogEventPublisherInternal publisher = InternalRegisterEvent(flag, eventName);
     return new LogEventPublisher(this, publisher);
 }
Пример #23
0
        /// <summary>
        /// Initializes an <see cref="LogEventPublisher"/> with a series of settings.
        /// </summary>
        /// <param name="attributes"></param>
        /// <param name="eventName">the name of the event.</param>
        /// <returns></returns>
        private LogEventPublisherInternal InternalRegisterEvent(LogMessageAttributes attributes, string eventName)
        {
            if (eventName == null)
                eventName = string.Empty;
            LogEventPublisherInternal publisher;
            if (m_lookupEventPublishers.TryGetValue(Tuple.Create(attributes, eventName), out publisher))
            {
                return publisher;
            }

            //If messages events are unclassified allow a higher message throughput rate.
            double messagesPerSecond = 1;
            int burstRate = 20;
            if (eventName.Length == 0)
            {
                messagesPerSecond = 5;
                burstRate = 100;
            }
            return InternalRegisterNewEvent(attributes, eventName, 0, messagesPerSecond, burstRate);
        }