Example #1
0
        /// <inheritdoc />
        public bool TryGetValue <T>(IColumnDescriptor <T> column, out T value)
        {
            if (!_columns.Contains(column))
            {
                value = column.DefaultValue;
                return(false);
            }

            return(_logEntry.TryGetValue(column, out value));
        }
            public bool TryGetValue <T>(IColumnDescriptor <T> column, out T value)
            {
                if (Equals(column, Core.Columns.Timestamp))
                {
                    value = (T)(object)_timestamp;
                    return(true);
                }

                if (Equals(column, Core.Columns.LogLevel))
                {
                    value = (T)(object)_logLevel;
                    return(true);
                }

                return(_inner.TryGetValue(column, out value));
            }
Example #3
0
            public void Add(IReadOnlyLogEntry logEntry)
            {
                T value;

                _data.Add(logEntry.TryGetValue(_column, out value)
                                        ? value
                                        : _column.DefaultValue);
            }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="entry"></param>
        /// <returns>A copy of the log entry as it was entered into this log file with all columns of this file (columns not present in the given log entry will be set to their default value).</returns>
        public IReadOnlyLogEntry Add(IReadOnlyLogEntry entry)
        {
            lock (_syncRoot)
            {
                entry.TryGetValue(Core.Columns.Timestamp, out var timestamp);
                UpdateTimestampProperties(timestamp);
                var logEntryIndex = GetLogEntryIndex(timestamp, out var elapsed, out var deltaTime);

                // The user supplies us with a list of properties to add, however we will
                // never allow the user to supply us things like index or line number.
                // Therefore we create a log entry which we actually want to add...
                var finalLogEntry = new LogEntry(Columns);

                foreach (var column in Columns)
                {
                    object value;
                    if (entry.TryGetValue(column, out value))
                    {
                        finalLogEntry.SetValue(column, value);
                    }
                }

                finalLogEntry.Index              = _logBuffer.Count;
                finalLogEntry.OriginalIndex      = _logBuffer.Count;
                finalLogEntry.LineNumber         = _logBuffer.Count + 1;
                finalLogEntry.OriginalLineNumber = _logBuffer.Count + 1;
                finalLogEntry.LogEntryIndex      = logEntryIndex;
                finalLogEntry.Timestamp          = timestamp;
                finalLogEntry.ElapsedTime        = elapsed;
                finalLogEntry.DeltaTime          = deltaTime;

                _logBuffer.Add(finalLogEntry);
                SetValue(Core.Properties.LogEntryCount, _logBuffer.Count);
                SetValue(TextProperties.MaxCharactersInLine, Math.Max(GetProperty(TextProperties.MaxCharactersInLine), finalLogEntry.RawContent?.Length ?? 0));
                Touch();
                _listeners.OnRead(_logBuffer.Count);

                return(finalLogEntry);
            }
        }
Example #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="entry"></param>
        public void Add(IReadOnlyLogEntry entry)
        {
            lock (_syncRoot)
            {
                DateTime?timestamp;
                entry.TryGetValue(LogFileColumns.Timestamp, out timestamp);
                LogEntryIndex logEntryIndex;
                TimeSpan?     elapsed, deltaTime;
                if (_logEntries.Count > 0)
                {
                    var last = _logEntries[_logEntries.Count - 1];

                    logEntryIndex = last.LogEntryIndex + 1;
                    elapsed       = timestamp - _properties.GetValue(LogFileProperties.StartTimestamp);
                    deltaTime     = timestamp - last.Timestamp;
                }
                else
                {
                    logEntryIndex = 0;
                    elapsed       = null;
                    deltaTime     = null;
                }

                if (_properties.GetValue(LogFileProperties.StartTimestamp) == null)
                {
                    _properties.SetValue(LogFileProperties.StartTimestamp, timestamp);
                }
                if (timestamp != null)
                {
                    _properties.SetValue(LogFileProperties.EndTimestamp, timestamp);
                }

                // The user supplies us with a list of properties to add, however we will
                // never allow the user to supply us things like index or line number.
                // Therefore we create a log entry which we actually want to add...
                var finalLogEntry = new LogEntry2(Columns);

                foreach (var column in Columns)
                {
                    object value;
                    if (entry.TryGetValue(column, out value))
                    {
                        finalLogEntry.SetValue(column, value);
                    }
                }

                finalLogEntry.Index              = _logEntries.Count;
                finalLogEntry.OriginalIndex      = _logEntries.Count;
                finalLogEntry.LineNumber         = _logEntries.Count + 1;
                finalLogEntry.OriginalLineNumber = _logEntries.Count + 1;
                finalLogEntry.LogEntryIndex      = logEntryIndex;
                finalLogEntry.Timestamp          = timestamp;
                finalLogEntry.ElapsedTime        = elapsed;
                finalLogEntry.DeltaTime          = deltaTime;

                _logEntries.Add(finalLogEntry);
                MaxCharactersPerLine = Math.Max(MaxCharactersPerLine, finalLogEntry.RawContent?.Length ?? 0);
                Touch();
                _listeners.OnRead(_logEntries.Count);
            }
        }