/// <summary>
        /// Reads a log message from the specified sqlite reader.
        /// </summary>
        /// <param name="reader">Sqlite reader to read from.</param>
        /// <param name="message">Receives the read log message.</param>
        private void ReadMessage(SQLiteDataReader reader, out LogFileMessage message)
        {
            // columns in result:
            // 0 = message id
            // 1 = timestamp
            // 2 = timezone offset
            // 3 = high precision timestamp
            // 4 = lost message count
            // 5 = process id
            // 6 = process name
            // 7 = application name
            // 8 = log writer name
            // 9 = log level name
            // 10 = has tags
            // 11 = text name
            long   messageId              = reader.GetInt64(0);
            var    timezoneOffset         = TimeSpan.FromTicks(reader.GetInt64(2));
            var    timestamp              = new DateTimeOffset(reader.GetInt64(1) + timezoneOffset.Ticks, timezoneOffset);
            long   highPrecisionTimestamp = reader.GetInt64(3);
            int    lostMessageCount       = reader.GetInt32(4);
            int    processId              = reader.GetInt32(5);
            string processName            = reader.GetString(6);
            string applicationName        = reader.GetString(7);
            string logWriterName          = reader.GetString(8);
            string logLevelName           = reader.GetString(9);
            bool   hasTags = reader.GetBoolean(10);
            string text    = reader.GetString(11);

            message = new LogFileMessage().InitWith(
                messageId,
                timestamp,
                highPrecisionTimestamp,
                lostMessageCount,
                mStringPool.Intern(logWriterName),
                mStringPool.Intern(logLevelName),
                TagSet.Empty,
                mStringPool.Intern(applicationName),
                mStringPool.Intern(processName),
                processId,
                text);

            // initialize tags, if there are tags associated with the message
            if (hasTags)
            {
                message.Tags = mAccessor.GetTagsOfMessage(messageId);
            }

            // protect message from changes
            message.Protect();
        }
Esempio n. 2
0
        public void GetNextMessage(
            bool isGloballyEnabled,
            LogMessageField enabledSpecificFilters,
            LogMessageField matchingSpecificFilters,
            MatchBehavior matchBehavior,
            double startIdRatio)
        {
            CreateFilterAndReferencePredicate(
                isGloballyEnabled,
                enabledSpecificFilters,
                matchingSpecificFilters,
                matchBehavior,
                out var collection,
                out var filter,
                out var unfilteredMessages,
                out var filteredMessages);

            // calculate the id where to start searching
            long startId = (long)(startIdRatio * (unfilteredMessages.Length - 1));

            // determine the message that is expected to be returned
            LogFileMessage expectedMessage = null;             // assume no match at start, revise later

            for (int i = filteredMessages.Length - 1; i >= 0; i--)
            {
                var message = filteredMessages[i];
                if (message.Id < startId)
                {
                    break;
                }
                expectedMessage = message;
            }

            using (collection)
                using (filter)
                {
                    var found = filter.GetNextMessage(startId);
                    Assert.Equal(expectedMessage, found);
                }
        }