Ejemplo n.º 1
0
        public void SaveEventPublisherDetails(Stream stream, LogEventPublisherDetails publisherDetails)
        {
            if (publisherDetails == null)
            {
                throw new ArgumentNullException(nameof(publisherDetails));
            }

            if (m_isSimple)
            {
                stream.Write((byte)0);
                publisherDetails.Save(stream, this);
            }
            else
            {
                int lookupId;
                if (m_ownerSaveLookup.TryGetValue(publisherDetails, out lookupId))
                {
                    stream.Write((byte)1);
                    stream.Write(lookupId);
                }
                else
                {
                    lookupId = m_ownerSaveLookup.Count;
                    stream.Write((byte)3);
                    publisherDetails.Save(stream, this);
                    m_ownerSaveLookup.Add(publisherDetails, lookupId);
                }
            }
        }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
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;
        }
Ejemplo n.º 4
0
        public LogEventPublisherDetails LoadEventPublisherDetails(Stream stream)
        {
            byte version = stream.ReadNextByte();

            switch (version)
            {
            case 0:
                return(new LogEventPublisherDetails(stream, this));

            case 1:
            {
                if (m_isSimple)
                {
                    throw new Exception("Cannot load without a LogMessageSaveHelper");
                }
                int id = stream.ReadInt32();
                return(m_ownerLoadLookup[id]);
            }

            case 2:
            {
                if (m_isSimple)
                {
                    throw new Exception("Cannot load without a LogMessageSaveHelper");
                }
                int id      = stream.ReadInt32();
                var details = new LogEventPublisherDetails(stream, this);
                m_ownerLoadLookup.Add(details);
                return(details);
            }

            case 3:
            {
                if (m_isSimple)
                {
                    throw new Exception("Cannot load without a LogMessageSaveHelper");
                }
                var details = new LogEventPublisherDetails(stream, this);
                m_ownerLoadLookup.Add(details);
                return(details);
            }

            default:
                throw new VersionNotFoundException();
            }
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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();
            }
        }
Ejemplo n.º 7
0
 public MessageByOwner(LogEventPublisherDetails owner)
 {
     m_index     = 0;
     Owner       = owner;
     AllMessages = new List <MessageData>();
 }