コード例 #1
0
        public void Evaluate__FromLevel_ToLevel()
        {
            var fromLevel = new SeverityLevel();
            fromLevel.Value = 13;

            var toLevel = new SeverityLevel();
            toLevel.Value = 69;

            SeverityFilter lf = new SeverityFilter();
            lf.From = fromLevel;
            lf.To = toLevel;

            var loggerName = new LoggerName("");

            using (ShimsContext.Create())
            {
                var de = new SquaredInfinity.Diagnostics.Entities.Fakes.ShimDiagnosticEvent();

                lf.Mode = FilterMode.Include;

                //# lower level
                de.SeverityGet = () => new SeverityLevel { Value = 12 };
                Assert.AreEqual(false, lf.Evaluate(de, loggerName));

                //# lower boundary level
                de.SeverityGet = () => new SeverityLevel { Value = 13 };
                Assert.AreEqual(true, lf.Evaluate(de, loggerName));

                //# upper boundary level
                de.SeverityGet = () => new SeverityLevel { Value = 69 };
                Assert.AreEqual(true, lf.Evaluate(de, loggerName));

                //# higher level
                de.SeverityGet = () => new SeverityLevel { Value = 70 };
                Assert.AreEqual(false, lf.Evaluate(de, loggerName));

                lf.Mode = FilterMode.Exclude;

                //# lower level
                de.SeverityGet = () => new SeverityLevel { Value = 12 };
                Assert.AreEqual(true, lf.Evaluate(de, loggerName));

                //# lower boundary level
                de.SeverityGet = () => new SeverityLevel { Value = 13 };
                Assert.AreEqual(false, lf.Evaluate(de, loggerName));

                //# upper boundary level
                de.SeverityGet = () => new SeverityLevel { Value = 69 };
                Assert.AreEqual(false, lf.Evaluate(de, loggerName));

                //# higher level
                de.SeverityGet = () => new SeverityLevel { Value = 70 };
                Assert.AreEqual(true, lf.Evaluate(de, loggerName));
            }
        }
コード例 #2
0
        void AssertLoggingOutcome(IReadOnlyList<DiagnosticEvent> events, SeverityLevel severity, string message, Exception exception, object attached1, object attached2)
        {
            Assert.AreEqual(1, events.Count);

            var ev = events.Single();

            Assert.AreEqual(exception, ev.ExceptionObject);
            Assert.AreEqual(exception != null, ev.HasException);
            Assert.AreEqual(severity, ev.Severity);
            Assert.AreEqual(message, ev.Message);
            Assert.AreEqual(message != null, ev.HasMessage);

            var attachedCount = 0;
            if (attached1 != null)
            {
                attachedCount++;

                var isAttached =
                    (from ao in ev.AttachedObjects
                     where ao.Value == attached1
                     select ao).Any();

                Assert.IsTrue(isAttached);
            }
            if (attached2 != null)
            {
                attachedCount++;

                var isAttached =
                    (from ao in ev.AttachedObjects
                     where ao.Value == attached2
                     select ao).Any();

                Assert.IsTrue(isAttached);
            }

            Assert.AreEqual(attachedCount, ev.AttachedObjects.Count);
        }
コード例 #3
0
        void ILogger.Event(SeverityLevel severity, string category, params object[] attachedObjects)
        {
            // TODO:
            //if (!Config.LogConfigCache.ShouldProcessErrors)
              //  return;

            var de =
                DiagnosticEvent.PrepareDiagnosticEvent(
                    severity,
                    category:category,
                    attachedObjects: attachedObjects.Select((o) => new AttachedObject(o)).ToArray());

            ((ILogger)this).ProcessDiagnosticEvent(de);
        }
コード例 #4
0
        public void Evaluate__ToLevel_Only()
        {
            var level = new SeverityLevel();
            level.Value = 13;

            SeverityFilter lf = new SeverityFilter();
            lf.To = level;

            var loggerName = new LoggerName("");

            using (ShimsContext.Create())
            {
                var de = new SquaredInfinity.Diagnostics.Entities.Fakes.ShimDiagnosticEvent();

                lf.Mode = FilterMode.Include;

                //# lower level
                de.SeverityGet = () => new SeverityLevel { Value = 12 };
                Assert.AreEqual(true, lf.Evaluate(de, loggerName));

                //# exact level
                de.SeverityGet = () => new SeverityLevel { Value = 13 };
                Assert.AreEqual(true, lf.Evaluate(de, loggerName));

                //# higher level
                de.SeverityGet = () => new SeverityLevel { Value = 14 };
                Assert.AreEqual(false, lf.Evaluate(de, loggerName));

                lf.Mode = FilterMode.Exclude;

                //# lower level
                de.SeverityGet = () => new SeverityLevel { Value = 12 };
                Assert.AreEqual(false, lf.Evaluate(de, loggerName));

                //# exact level
                de.SeverityGet = () => new SeverityLevel { Value = 13 };
                Assert.AreEqual(false, lf.Evaluate(de, loggerName));

                //# higher level
                de.SeverityGet = () => new SeverityLevel { Value = 14 };
                Assert.AreEqual(true, lf.Evaluate(de, loggerName));
            }
        }
コード例 #5
0
        void ILogger.Event(SeverityLevel severity, string category)
        {
            // TODO:
            //if (!Config.LogConfigCache.ShouldProcessErrors)
              //  return;

            var de =
                DiagnosticEvent.PrepareDiagnosticEvent(
                    severity,
                    category: category);

            ((ILogger)this).ProcessDiagnosticEvent(de);
        }