public void TestTagListWildcard()
        {
            var config = new LoggingConfig();
            config.LoadConfig();
            var dispatcher = new LogEventDispatcher(config);
            var tagKeeper = dispatcher.TagKeeper;

            Assert.IsTrue(tagKeeper.CheckMatch("helloworld", "hello*"));
        }
        public void TestTagList()
        {
            var config = new LoggingConfig();
            config.LoadConfig();
            var dispatcher = new LogEventDispatcher(config);

            var tagList = new List<string> { "fatal", "error", "warn", "info", "debug", "trace" };
            var tagKeeper = dispatcher.TagKeeper;
            for (int lp = 0; lp < tagList.Count - 1; lp++)
                for (int lp2 = lp + 1; lp2 < tagList.Count; lp2++)
                    Assert.IsTrue(tagKeeper.CheckMatch(tagList[lp], tagList[lp2]), String.Format("Checking {0} = {1}", tagList[lp2], tagList[lp]));
        }
示例#3
0
        public void TestStrictIncludeRule()
        {
            var config = new LoggingConfig();
            config.LoadConfig(@"Configs\StrictIncludeRuleTest.json");
            var dispatcher = new LogEventDispatcher(config);
            var ruleKeeper = dispatcher.RuleKeeper;

            var strictTargets = ruleKeeper.GetTargetsForTags(new List<string> { this.GetType().FullName, "info" });
            Assert.IsNotNull(strictTargets);
            Assert.IsTrue(strictTargets.Count == 1);
            Assert.IsTrue(strictTargets.Contains("console"));

            var incompleteTargets = ruleKeeper.GetTargetsForTags(new List<string> { "info" });
            Assert.IsNotNull(incompleteTargets);
            Assert.IsTrue(incompleteTargets.Count == 0);
        }
示例#4
0
        public void TestSimpleIncludeRule()
        {
            var config = new LoggingConfig();
            config.LoadConfig(@"Configs\SimpleIncludeRuleTest.json");
            var dispatcher = new LogEventDispatcher(config);
            var ruleKeeper = dispatcher.RuleKeeper;

            var infoTargets = ruleKeeper.GetTargetsForTags(new List<string> { "info" });
            Assert.IsNotNull(infoTargets);
            Assert.IsTrue(infoTargets.Count == 1);
            Assert.IsTrue(infoTargets.Contains("console"));

            var traceTargets = ruleKeeper.GetTargetsForTags(new List<string> { "trace" });
            Assert.IsNotNull(traceTargets);
            Assert.IsTrue(traceTargets.Count == 0);
        }
示例#5
0
        public void WatchTest()
        {
            using (var copy = new ConfigFileCopy(DefaultConfigFile))
            {
                var config = new LoggingConfig();
                config.LoadConfig(copy.FileName);

                Assert.IsTrue(config.Watch);

                SetWatch(copy.FileName, false);
                for (int lp = 0; lp < 50; lp++)
                {
                    if (!config.Watch)
                        break;
                    Thread.Sleep(100);
                }

                Assert.IsFalse(config.Watch);
            }
        }
示例#6
0
        public void TestMultipleRule()
        {
            var config = new LoggingConfig();
            config.LoadConfig(@"Configs\MultipleRuleTest.json");
            var dispatcher = new LogEventDispatcher(config);
            var ruleKeeper = dispatcher.RuleKeeper;

            var cond1Targets = ruleKeeper.GetTargetsForTags(new List<string> { "cond1" });
            Assert.IsNotNull(cond1Targets);
            Assert.IsTrue(cond1Targets.Count == 2);
            Assert.IsTrue(cond1Targets.Contains("target1"));
            Assert.IsTrue(cond1Targets.Contains("target2"));

            var cond2Targets = ruleKeeper.GetTargetsForTags(new List<string> { "cond2" });
            Assert.IsNotNull(cond2Targets);
            Assert.IsTrue(cond2Targets.Count == 1);
            Assert.IsTrue(cond2Targets.Contains("target2"));

            var cond3Targets = ruleKeeper.GetTargetsForTags(new List<string> { "cond3" });
            Assert.IsNotNull(cond3Targets);
            Assert.IsTrue(cond3Targets.Count == 1);
            Assert.IsTrue(cond3Targets.Contains("target1"));
        }
示例#7
0
        public void MalformedJSONTest()
        {
            // Initialize the failure test
            ConfigFailed = false;
            var config = new LoggingConfig()
            {
                ExceptionHandler = HandleException
            };
            ICollection<string> sourceLines;

            using (var copy = new ConfigFileCopy(DefaultConfigFile))
            {
                // Load the file
                config.LoadConfig(copy.FileName);

                // Break the file
                sourceLines = MalformnJSON(copy.FileName);

                // Check to see if the failure was detected
                int checkCount = 0;
                while (!ConfigFailed)
                {
                    Thread.Sleep(200);
                    if (checkCount++ > 5)
                        break;
                }
                Assert.IsTrue(ConfigFailed);

                // Next we need to see if we can recover from the error

                // Restore the file
                WriteFile(copy.FileName, sourceLines);

                // Make sure that watch is on
                Assert.IsTrue(config.Watch);

                // Turn off watch
                SetWatch(copy.FileName, false);
                for (int lp = 0; lp < 10; lp++)
                {
                    if (!config.Watch)
                        break;
                    Thread.Sleep(100);
                }

                // Make sure watch is off
                Assert.IsFalse(config.Watch);
            }
        }
示例#8
0
 public void InitializeTest()
 {
     var config = new LoggingConfig();
     config.LoadConfig();
 }
示例#9
0
        public void TestComplexRule()
        {
            var config = new LoggingConfig();
            config.LoadConfig(@"Configs\ComplexRuleTest.json");
            var dispatcher = new LogEventDispatcher(config);
            var ruleKeeper = dispatcher.RuleKeeper;

            var infoTargets = ruleKeeper.GetTargetsForTags(new List<string> { "info", this.GetType().FullName });
            Assert.IsNotNull(infoTargets);
            Assert.IsTrue(infoTargets.Count == 1);
            Assert.IsTrue(infoTargets.Contains("console"));

            var traceTargets = ruleKeeper.GetTargetsForTags(new List<string> { "trace", this.GetType().FullName });
            Assert.IsNotNull(traceTargets);
            Assert.IsTrue(traceTargets.Count == 0);

            var infoTargetTargets = ruleKeeper.GetTargetsForTags(new List<string> { "info", "NuLog.Targets", this.GetType().FullName });
            Assert.IsNotNull(infoTargetTargets);
            Assert.IsTrue(infoTargetTargets.Count == 0);
        }