/// <summary>
        /// Get logs by a specific attribute.
        /// </summary>
        /// <param name="registry">Log registry</param>
        /// <param name="attribute">The attribute to get entries by.</param>
        /// <returns>Logs grouped by the specified attribute.</returns>
        public static IObservable <IGroupedObservable <object, ILogEntry> > GetBy(this ILogRegistry registry, LogAttribute attribute)
        {
            getByCounter.Increment(attribute.ToString());

            if (attribute == LogAttribute.Timestamp)
            {
                return(null);
            }
            // Special case to ensure that message and timestamp (which doesn't work here anyway) match the expected types
            return(from log in registry.Logs
                   where log.HasAttribute(attribute) && (log.IsValid || !(attribute == LogAttribute.Message && !(log.GetAttribute <object>(attribute) is string)))
                   group log by log.GetAttribute <object>(attribute));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Add an attribute value to the log entry.
        /// </summary>
        /// <param name="entry">The entry to add an attribute to.</param>
        /// <param name="attribute">The attribute to add to.</param>
        /// <param name="value">The attribute value to add.</param>
        /// <returns><c>true</c> if the entry was added. <c>false</c> if otherwise.</returns>
        public bool AddValueToLog(ILogEntry entry, LogAttribute attribute, object value)
        {
            if (value == null)
            {
                return(false);
            }
            addValueToLogCounter.Increment(attribute.ToString());

            if (entry is IInternalLogEntry internalEntry && !entry.HasAttribute(attribute))
            {
                addValueToLogAddingCounter.Increment();
                internalEntry.AddAttribute(attribute, value);
                return(true);
            }
            return(false);
        }