コード例 #1
0
        private void ValidateTestLog(LogLevel logLevel, LoggableFormat loggableFormat)
        {
            var currentTestContext = TestCorrelator.GetLogEventsFromCurrentContext().ToList();

            if (logLevel <= LogLevel.Information)
            {
                currentTestContext.Should().ContainSingle().Which.Properties.ContainsKey(TestProperty).Should()
                .BeTrue();
                currentTestContext.Should().ContainSingle().Which.Properties[TestProperty].ToString().Should()
                .Be(TestValue.ToDoubleQuoted());
            }
            else
            {
                currentTestContext.Should().ContainSingle().Which.Properties.ContainsKey(TestProperty).Should()
                .BeFalse();
            }

            if (loggableFormat.IsWithParents() && logLevel <= LogLevel.Debug)
            {
                currentTestContext.Should().ContainSingle().Which.Properties.ContainsKey(TestPropertyParent).Should().BeTrue();
                currentTestContext.Should().ContainSingle().Which.Properties[TestPropertyParent].ToString().Should().Be(ParentTestValue.ToDoubleQuoted());
            }
            else
            {
                currentTestContext.Should().ContainSingle().Which.Properties.ContainsKey(TestPropertyParent).Should().BeFalse();
            }

            currentTestContext.Should().ContainSingle().Which.MessageTemplate.Text.Should().Be(TestLogMsg);
        }
コード例 #2
0
        /// <summary>
        /// Gets the log property list level.
        /// </summary>
        /// <param name="logLevel">The log level.</param>
        /// <param name="loggableFormat">The loggable format.</param>
        /// <returns>IEnumerable&lt;IPureLogPropertyLevel&gt;.</returns>
        /// <autogeneratedoc />
        public override IEnumerable <IPureLogPropertyLevel> GetLogPropertyListLevel(LogLevel logLevel,
                                                                                    LoggableFormat loggableFormat)
        {
            var logProperties = new List <IPureLogPropertyLevel>
            {
                new PureLogPropertyLevel("DiscoveredDevices", _physical2ArpItem.Count, LogLevel.Information),
                new PureLogPropertyLevel("ArpLastRefreshStatus", LastArpRefreshStatus, LogLevel.Information),
                new PureLogPropertyLevel("ArpLastUpdated", LastUpdated, LogLevel.Information)
            };

            if (logLevel <= LogLevel.Debug)
            {
                lock (_updateLock)
                {
                    var arpItems = this.ToList();

                    foreach (var arpItem in arpItems)
                    {
                        logProperties.Add(new PureLogPropertyLevel(arpItem.IPAddress.ToString(), arpItem.PhysicalAddress.ToDashString(), LogLevel.Information));
                    }
                }
            }

            return(logProperties.Where(p => p.MinimumLogLevel.CompareTo(logLevel) >= 0));
        }
コード例 #3
0
ファイル: PureLoggableBase.cs プロジェクト: Kiphaz/PureActive
        /// <summary>
        /// Gets the log property list level.
        /// </summary>
        /// <param name="logLevel">The log level.</param>
        /// <param name="loggableFormat">The loggable format.</param>
        /// <returns>IEnumerable&lt;IPureLogPropertyLevel&gt;.</returns>
        /// <autogeneratedoc />
        public virtual IEnumerable <IPureLogPropertyLevel> GetLogPropertyListLevel(LogLevel logLevel,
                                                                                   LoggableFormat loggableFormat)
        {
            var logProperties = new List <IPureLogPropertyLevel>
            {
                new PureLogPropertyLevel("ObjectType", TypeNameHelper.GetTypeDisplayName(GetType()),
                                         LogLevel.Information)
            };

            return(logProperties.Where(p => p.MinimumLogLevel.CompareTo(logLevel) >= 0));
        }
コード例 #4
0
        /// <summary>
        /// Pushes the log properties.
        /// </summary>
        /// <param name="loggable">The loggable.</param>
        /// <param name="pureLogLevel">The pure log level.</param>
        /// <param name="loggableFormat">The loggable format.</param>
        /// <returns>IDisposable.</returns>
        /// <exception cref="ArgumentNullException">loggable</exception>
        /// <autogeneratedoc />
        public static IDisposable PushLogProperties(this IPureLoggable loggable, IPureLogLevel pureLogLevel,
                                                    LoggableFormat loggableFormat = LoggableFormat.ToLog)
        {
            if (loggable == null)
            {
                throw new ArgumentNullException(nameof(loggable));
            }
            if (pureLogLevel == null)
            {
                throw new ArgumentNullException(nameof(pureLogLevel));
            }

            return(PushLogProperties(loggable, pureLogLevel.MinimumLogLevel, loggableFormat));
        }
コード例 #5
0
        /// <summary>
        /// Gets the log property list level.
        /// </summary>
        /// <param name="logLevel">The log level.</param>
        /// <param name="loggableFormat">The loggable format.</param>
        /// <returns>IEnumerable&lt;IPureLogPropertyLevel&gt;.</returns>
        /// <autogeneratedoc />
        public override IEnumerable <IPureLogPropertyLevel> GetLogPropertyListLevel(LogLevel logLevel,
                                                                                    LoggableFormat loggableFormat)
        {
            var logPropertyLevels = loggableFormat.IsWithParents()
                ? base.GetLogPropertyListLevel(logLevel, loggableFormat)?.ToList()
                : new List <IPureLogPropertyLevel>();

            if (logLevel <= LogLevel.Information)
            {
                logPropertyLevels?.Add(new PureLogPropertyLevel(nameof(DeviceType), DeviceType, LogLevel.Information));
            }

            return(logPropertyLevels);
        }
コード例 #6
0
        /// <summary>
        /// Pushes the log properties.
        /// </summary>
        /// <param name="loggable">The loggable.</param>
        /// <param name="minimumLogLevel">The minimum log level.</param>
        /// <param name="loggableFormat">The loggable format.</param>
        /// <returns>IDisposable.</returns>
        /// <exception cref="ArgumentNullException">
        /// loggable
        /// or
        /// Logger
        /// </exception>
        /// <autogeneratedoc />
        public static IDisposable PushLogProperties(this IPureLoggable loggable, LogLevel minimumLogLevel,
                                                    LoggableFormat loggableFormat = LoggableFormat.ToLog)
        {
            if (loggable == null)
            {
                throw new ArgumentNullException(nameof(loggable));
            }
            if (loggable.Logger == null)
            {
                throw new ArgumentNullException(nameof(loggable.Logger));
            }

            return(loggable.Logger.PushLogProperties(loggable.GetLogPropertyListLevel(minimumLogLevel, loggableFormat),
                                                     minimumLogLevel));
        }
コード例 #7
0
        /// <summary>
        /// Gets the log property list level.
        /// </summary>
        /// <param name="logLevel">The log level.</param>
        /// <param name="loggableFormat">The loggable format.</param>
        /// <returns>IEnumerable&lt;IPureLogPropertyLevel&gt;.</returns>
        /// <autogeneratedoc />
        public override IEnumerable <IPureLogPropertyLevel> GetLogPropertyListLevel(LogLevel logLevel,
                                                                                    LoggableFormat loggableFormat)
        {
            var logPropertyLevels = loggableFormat.IsWithParents()
                ? base.GetLogPropertyListLevel(logLevel, loggableFormat)?.ToList()
                : new List <IPureLogPropertyLevel>();

            if (logLevel <= LogLevel.Information)
            {
                logPropertyLevels?.Add(new PureLogPropertyLevel($"{ServiceHost}HostStatus", ServiceHostStatus,
                                                                LogLevel.Information));
            }

            return(logPropertyLevels?.Where(p => p.MinimumLogLevel.CompareTo(logLevel) >= 0));
        }
コード例 #8
0
ファイル: CommonServices.cs プロジェクト: Kiphaz/PureActive
        /// <summary>
        /// Gets the log property list level.
        /// </summary>
        /// <param name="logLevel">The log level.</param>
        /// <param name="loggableFormat">The loggable format.</param>
        /// <returns>IEnumerable&lt;IPureLogPropertyLevel&gt;.</returns>
        /// <autogeneratedoc />
        public override IEnumerable <IPureLogPropertyLevel> GetLogPropertyListLevel(LogLevel logLevel,
                                                                                    LoggableFormat loggableFormat)
        {
            var logPropertyLevels = loggableFormat.IsWithParents()
                ? base.GetLogPropertyListLevel(logLevel, loggableFormat)?.ToList()
                : new List <IPureLogPropertyLevel>();

            if (logLevel <= LogLevel.Information)
            {
                logPropertyLevels?.Add(new PureLogPropertyLevel("CommonServicesHostStatus", ServiceHostStatus,
                                                                LogLevel.Information));
            }

            return(logPropertyLevels);
        }
コード例 #9
0
ファイル: PureObjectBase.cs プロジェクト: Kiphaz/PureActive
        /// <summary>
        /// Gets the log property list level.
        /// </summary>
        /// <param name="logLevel">The log level.</param>
        /// <param name="loggableFormat">The loggable format.</param>
        /// <returns>IEnumerable&lt;IPureLogPropertyLevel&gt;.</returns>
        /// <autogeneratedoc />
        public override IEnumerable <IPureLogPropertyLevel> GetLogPropertyListLevel(LogLevel logLevel,
                                                                                    LoggableFormat loggableFormat)
        {
            var logPropertyLevels = loggableFormat.IsWithParents()
                ? base.GetLogPropertyListLevel(logLevel, loggableFormat)?.ToList()
                : new List <IPureLogPropertyLevel>();

            if (logLevel <= LogLevel.Information)
            {
                logPropertyLevels?.Add(new PureLogPropertyLevel(nameof(ObjectId), ObjectId, LogLevel.Information));
                logPropertyLevels?.Add(new PureLogPropertyLevel(nameof(ObjectVersion), ObjectVersion,
                                                                LogLevel.Information));
                logPropertyLevels?.Add(new PureLogPropertyLevel(nameof(CreatedTimestamp), CreatedTimestamp,
                                                                LogLevel.Information));
                logPropertyLevels?.Add(new PureLogPropertyLevel(nameof(ModifiedTimestamp), ModifiedTimestamp,
                                                                LogLevel.Information));
            }

            return(logPropertyLevels?.Where(p => p.MinimumLogLevel.CompareTo(logLevel) >= 0));
        }
コード例 #10
0
        /// <summary>
        /// Formats the property list.
        /// </summary>
        /// <param name="sb">The sb.</param>
        /// <param name="loggableFormat">The loggable format.</param>
        /// <param name="logPropertyEnumerable">The log property enumerable.</param>
        /// <param name="minimumLogLevel">The minimum log level.</param>
        /// <exception cref="ArgumentNullException">
        /// sb
        /// or
        /// logPropertyEnumerable
        /// </exception>
        /// <autogeneratedoc />
        public static void FormatPropertyList(StringBuilder sb, LoggableFormat loggableFormat,
                                              IEnumerable <IPureLogPropertyLevel> logPropertyEnumerable, LogLevel minimumLogLevel = LogLevel.Debug)
        {
            if (sb == null)
            {
                throw new ArgumentNullException(nameof(sb));
            }
            if (logPropertyEnumerable == null)
            {
                throw new ArgumentNullException(nameof(logPropertyEnumerable));
            }

            var logPropertyList = logPropertyEnumerable.ToList();
            var maxLength       = logPropertyList.Select(p => p.Key).MaxStringLength() + 2;

            foreach (var logPropertyListItem in logPropertyList)
            {
                if (logPropertyListItem.MinimumLogLevel.CompareTo(minimumLogLevel) >= 0)
                {
                    sb.AppendLine(
                        $"{logPropertyListItem.Key.PadWithDelim(": ", maxLength)}{logPropertyListItem.Value}");
                }
            }
        }
コード例 #11
0
            public override IEnumerable <IPureLogPropertyLevel> GetLogPropertyListLevel(LogLevel logLevel,
                                                                                        LoggableFormat loggableFormat)
            {
                var logPropertyLevels = loggableFormat.IsWithParents()
                    ? base.GetLogPropertyListLevel(logLevel, loggableFormat)?.ToList()
                    : new List <IPureLogPropertyLevel>();

                if (logLevel <= LogLevel.Debug)
                {
                    logPropertyLevels?.Add(new PureLogPropertyLevel(nameof(ParentStringValue), ParentStringValue, LogLevel.Information));
                }

                return(logPropertyLevels?.Where(p => p.MinimumLogLevel.CompareTo(logLevel) >= 0));
            }
コード例 #12
0
        private IEnumerable <KeyValuePair <string, object> > CreateTestPropertyList(LogLevel logLevel, LoggableFormat loggableFormat)
        {
            var testPropertyList = new List <KeyValuePair <string, object> >();

            if (logLevel <= LogLevel.Information)
            {
                testPropertyList.Add(new KeyValuePair <string, object>(TestProperty, TestValue));
            }


            if (loggableFormat.IsWithParents() && logLevel <= LogLevel.Debug)
            {
                testPropertyList.Add(new KeyValuePair <string, object>(TestPropertyParent, ParentTestValue));
            }

            return(testPropertyList);
        }
コード例 #13
0
 /// <summary>
 /// Determines whether [is to log] [the specified loggable format].
 /// </summary>
 /// <param name="loggableFormat">The loggable format.</param>
 /// <returns><c>true</c> if [is to log] [the specified loggable format]; otherwise, <c>false</c>.</returns>
 /// <autogeneratedoc />
 public static bool IsToLog(this LoggableFormat loggableFormat) =>
 (loggableFormat & LoggableFormat.ToLog) > 0;
コード例 #14
0
ファイル: PureLoggableBase.cs プロジェクト: Kiphaz/PureActive
        /// <summary>
        /// Formats the log string.
        /// </summary>
        /// <param name="sb">The sb.</param>
        /// <param name="logLevel">The log level.</param>
        /// <param name="loggableFormat">The loggable format.</param>
        /// <returns>StringBuilder.</returns>
        /// <autogeneratedoc />
        public virtual StringBuilder FormatLogString(StringBuilder sb, LogLevel logLevel, LoggableFormat loggableFormat)
        {
            PureLogPropertyLevel.FormatPropertyList(sb, loggableFormat,
                                                    GetLogPropertyListLevel(logLevel, loggableFormat), logLevel);

            return(sb);
        }
コード例 #15
0
ファイル: PureLoggableBase.cs プロジェクト: Kiphaz/PureActive
        /// <summary>
        /// Returns a <see cref="string" /> that represents this instance.
        /// </summary>
        /// <param name="logLevel">The log level.</param>
        /// <param name="loggableFormat">The loggable format.</param>
        /// <returns>A <see cref="string" /> that represents this instance.</returns>
        /// <autogeneratedoc />
        public virtual string ToString(LogLevel logLevel, LoggableFormat loggableFormat)
        {
            var sb = new StringBuilder();

            return(FormatLogString(sb, logLevel, loggableFormat).ToString());
        }
コード例 #16
0
 /// <summary>
 /// Gets the log property list level.
 /// </summary>
 /// <param name="pingReply">The ping reply.</param>
 /// <param name="logLevel">The log level.</param>
 /// <param name="loggableFormat">The loggable format.</param>
 /// <returns>IEnumerable&lt;IPureLogPropertyLevel&gt;.</returns>
 /// <autogeneratedoc />
 public static IEnumerable <IPureLogPropertyLevel> GetLogPropertyListLevel(this PingReply pingReply,
                                                                           LogLevel logLevel, LoggableFormat loggableFormat)
 {
     return(new List <IPureLogPropertyLevel>
     {
         new PureLogPropertyLevel("Status", pingReply.Status, LogLevel.Information),
         new PureLogPropertyLevel("IPAddress", pingReply.Address, LogLevel.Information),
         new PureLogPropertyLevel("RoundtripTime", pingReply.RoundtripTime, LogLevel.Trace)
     }
            .Where(p => p.MinimumLogLevel.CompareTo(logLevel) >= 0));
 }
コード例 #17
0
 /// <summary>
 /// Determines whether [is with parents] [the specified loggable format].
 /// </summary>
 /// <param name="loggableFormat">The loggable format.</param>
 /// <returns><c>true</c> if [is with parents] [the specified loggable format]; otherwise, <c>false</c>.</returns>
 /// <autogeneratedoc />
 public static bool IsWithParents(this LoggableFormat loggableFormat) =>
 (loggableFormat & LoggableFormat.WithParents) > 0;