CleanupFolder() public static method

public static CleanupFolder ( string folder ) : void
folder string
return void
Example #1
0
        public void FilteringBySource()
        {
            TestHelper.CleanupFolder(SystemActivityMonitor.RootLogPath + "FilteringBySource");

            using (GrandOutput g = new GrandOutput())
            {
                GrandOutputConfiguration config = new GrandOutputConfiguration();
                config.Load(XDocument.Parse(@"
<GrandOutputConfiguration>
    <Channel MinimalFilter=""Debug"">
        <Add Type=""BinaryFile"" Name=""All"" Path=""FilteringBySource"" />
        <Channel Name=""HiddenTopic"" MinimalFilter=""Off"" TopicRegex=""(hidden\s+topic|hide\s+this\s+topic)"" MatchOptions=""CultureInvariant, ExplicitCapture, Compiled, Multiline"" />
    </Channel>
    <SourceOverrideFilter>
        <Add File=""SourceFile-Debug.cs"" Filter=""Debug"" />
        <Add File=""SourceFile-Off.cs"" Filter=""Off"" />
        <Add File=""SourceFile-Strange.cs"" Filter=""{Trace,Fatal}"" />
    </SourceOverrideFilter>
</GrandOutputConfiguration>", LoadOptions.SetLineInfo).Root, TestHelper.ConsoleMonitor);

                Assert.That(g.SetConfiguration(config, TestHelper.ConsoleMonitor));

                var m = new ActivityMonitor(false);
                g.Register(m);

                m.Fatal(fileName: "SourceFile-Off.cs").Send("NOSHOW");
                m.SetTopic("This is a hidden topic...");
                m.Trace(0, "SourceFile-Debug.cs").Send("Trace-1");
                m.Trace().Send("NOSHOW");
                m.SetTopic("Please, hide this topic!");
                m.Trace(fileName: "SourceFile-Strange.cs").Send("NOSHOW");
                using (m.OpenTrace(fileName: "SourceFile-Strange.cs").Send("Trace-2"))
                {
                    m.Trace(fileName: "SourceFile-Strange.cs").Send("NOSHOW");
                    m.Fatal(fileName: "SourceFile-Strange.cs").Send("Fatal-1");
                    m.Fatal(fileName: "SourceFile-Off.cs").Send("NOSHOW");
                }
                m.SetTopic(null);
                m.Trace(fileName: "SourceFile-Strange.cs").Send("NOSHOW");
                m.Fatal(fileName: "SourceFile-Off.cs").Send("NOSHOW");
                m.Trace().Send("Trace-3");
            }
            List <StupidStringClient> logs = TestHelper.ReadAllLogs(new DirectoryInfo(SystemActivityMonitor.RootLogPath + "FilteringBySource"), false);

            Assert.That(logs.Count, Is.EqualTo(1));
            Assert.That(logs[0].ToString(), Does.Not.Contain("NOSHOW"));
            var texts = logs[0].Entries.Select(e => e.Text).ToArray();

            CollectionAssert.AreEqual(new string[] {
                "Trace-1",
                "Trace-2",
                "Fatal-1",
                ActivityMonitor.SetTopicPrefix,
                "Trace-3",
            }, texts, StringComparer.Ordinal);
        }
Example #2
0
        public void GrandOutputHasSameCompressedAndUncompressedLogs()
        {
            string rootPath = SystemActivityMonitor.RootLogPath + @"\GrandOutputGzip";

            TestHelper.CleanupFolder(rootPath);

            GrandOutputConfiguration c = new GrandOutputConfiguration();

            Assert.That(c.Load(XDocument.Parse(@"
                <GrandOutputConfiguration GlobalDefaultFilter=""Release"" >
                    <Channel>
                        <Add Type=""BinaryFile"" Name=""GzipGlobalCatch"" Path=""" + rootPath + @"\OutputGzip"" MaxCountPerFile=""200000"" UseGzipCompression=""True"" />
                        <Add Type=""BinaryFile"" Name=""RawGlobalCatch"" Path=""" + rootPath + @"\OutputRaw"" MaxCountPerFile=""200000"" UseGzipCompression=""False"" />
                    </Channel>
                </GrandOutputConfiguration>"
                                               ).Root, TestHelper.ConsoleMonitor));
            Assert.That(c.ChannelsConfiguration.Configurations.Count, Is.EqualTo(2));

            using (GrandOutput g = new GrandOutput())
            {
                Assert.That(g.SetConfiguration(c, TestHelper.ConsoleMonitor), Is.True);

                var taskA = Task.Factory.StartNew <int>(() => { DumpMonitorOutput(CreateMonitorAndRegisterGrandOutput("Task A", g)); return(1); });
                var taskB = Task.Factory.StartNew <int>(() => { DumpMonitorOutput(CreateMonitorAndRegisterGrandOutput("Task B", g)); return(1); });
                var taskC = Task.Factory.StartNew <int>(() => { DumpMonitorOutput(CreateMonitorAndRegisterGrandOutput("Task C", g)); return(1); });

                Task.WaitAll(taskA, taskB, taskC);
            }

            string[] gzipCkmons = TestHelper.WaitForCkmonFilesInDirectory(rootPath + @"\OutputGzip", 1);
            string[] rawCkmons  = TestHelper.WaitForCkmonFilesInDirectory(rootPath + @"\OutputRaw", 1);

            Assert.That(gzipCkmons, Has.Length.EqualTo(1));
            Assert.That(rawCkmons, Has.Length.EqualTo(1));

            FileInfo gzipCkmonFile = new FileInfo(gzipCkmons.Single());
            FileInfo rawCkmonFile  = new FileInfo(rawCkmons.Single());

            Assert.That(gzipCkmonFile.Exists, Is.True);
            Assert.That(rawCkmonFile.Exists, Is.True);

            // Test file size
            Assert.That(gzipCkmonFile.Length, Is.LessThan(rawCkmonFile.Length));

            // Test de-duplication between Gzip and non-Gzip
            MultiLogReader mlr      = new MultiLogReader();
            var            fileList = mlr.Add(new string[] { gzipCkmonFile.FullName, rawCkmonFile.FullName });

            Assert.That(fileList, Has.Count.EqualTo(2));

            var map = mlr.GetActivityMap();

            Assert.That(map.Monitors.Count, Is.EqualTo(3));
        }
Example #3
0
        public void dumping_text_file_with_multiple_monitors()
        {
            TestHelper.CleanupFolder(SystemActivityMonitor.RootLogPath + "TextFileMulti");
            Random r = new Random();

            using (GrandOutput g = new GrandOutput())
            {
                GrandOutputConfiguration config = new GrandOutputConfiguration();
                config.Load(XDocument.Parse(@"
<GrandOutputConfiguration>
    <Channel MinimalFilter=""Debug"">
        <Add Type=""TextFile"" Name=""All"" Path=""TextFileMulti"" />
    </Channel>
</GrandOutputConfiguration>", LoadOptions.SetLineInfo).Root, TestHelper.ConsoleMonitor);

                Assert.That(g.SetConfiguration(config, TestHelper.ConsoleMonitor));
                Parallel.Invoke(
                    () => DumpSampleLogs1(r, g),
                    () => DumpSampleLogs1(r, g),
                    () => DumpSampleLogs1(r, g),
                    () => DumpSampleLogs1(r, g),
                    () => DumpSampleLogs1(r, g),
                    () => DumpSampleLogs1(r, g),
                    () => DumpSampleLogs1(r, g),
                    () => DumpSampleLogs1(r, g),
                    () => DumpSampleLogs2(r, g),
                    () => DumpSampleLogs1(r, g),
                    () => DumpSampleLogs1(r, g),
                    () => DumpSampleLogs1(r, g),
                    () => DumpSampleLogs1(r, g),
                    () => DumpSampleLogs1(r, g),
                    () => DumpSampleLogs2(r, g),
                    () => DumpSampleLogs1(r, g),
                    () => DumpSampleLogs1(r, g),
                    () => DumpSampleLogs1(r, g),
                    () => DumpSampleLogs2(r, g)
                    );
            }
            FileInfo f    = new DirectoryInfo(SystemActivityMonitor.RootLogPath + "TextFileMulti").EnumerateFiles().Single();
            string   text = File.ReadAllText(f.FullName);

            Console.WriteLine(text);
        }
Example #4
0
        public void dumping_text_file()
        {
            TestHelper.CleanupFolder(SystemActivityMonitor.RootLogPath + "TextFile");
            Random r = new Random();

            using (GrandOutput g = new GrandOutput())
            {
                GrandOutputConfiguration config = new GrandOutputConfiguration();
                config.Load(XDocument.Parse(@"
<GrandOutputConfiguration>
    <Channel MinimalFilter=""Debug"">
        <Add Type=""TextFile"" Name=""All"" Path=""TextFile"" />
    </Channel>
</GrandOutputConfiguration>", LoadOptions.SetLineInfo).Root, TestHelper.ConsoleMonitor);

                Assert.That(g.SetConfiguration(config, TestHelper.ConsoleMonitor));

                DumpSampleLogs1(r, g);
                DumpSampleLogs2(r, g);
            }
            CheckSampleTextFile();
        }
Example #5
0
        public void ApplyEmptyAndDefaultConfig()
        {
            TestHelper.CleanupFolder(SystemActivityMonitor.RootLogPath + "ApplyEmptyAndDefaultConfig");

            using (GrandOutput g = new GrandOutput())
            {
                var m = new ActivityMonitor(false);
                g.Register(m);
                m.Trace().Send("NoShow-1");
                Assert.That(g.SetConfiguration(new GrandOutputConfiguration(), TestHelper.ConsoleMonitor));
                m.Trace().Send("NoShow-2");
                Assert.That(g.SetConfiguration(CreateDefaultConfig("ApplyEmptyAndDefaultConfig"), TestHelper.ConsoleMonitor));
                m.Trace().Send("Show-1");
                Assert.That(g.SetConfiguration(new GrandOutputConfiguration(), TestHelper.ConsoleMonitor));
                m.Trace().Send("NoShow-3");
            }
            var replayed = new ActivityMonitor(false);
            var c        = replayed.Output.RegisterClient(new StupidStringClient());

            TestHelper.ReplayLogs(new DirectoryInfo(SystemActivityMonitor.RootLogPath + "ApplyEmptyAndDefaultConfig"), true, mon => replayed, TestHelper.ConsoleMonitor);
            CollectionAssert.AreEqual(new[] { "<Missing log data>", "Show-1" }, c.Entries.Select(e => e.Text), StringComparer.OrdinalIgnoreCase);
        }
Example #6
0
        public void FilteringByTopic()
        {
            TestHelper.CleanupFolder(SystemActivityMonitor.RootLogPath + "FilteringByTopic");

            using (GrandOutput g = new GrandOutput())
            {
                GrandOutputConfiguration config = new GrandOutputConfiguration();
                config.Load(XDocument.Parse(@"
<GrandOutputConfiguration>
    <Channel MinimalFilter=""Debug"">
        <Add Type=""BinaryFile"" Name=""All"" Path=""FilteringByTopic"" />
        <Channel Name=""HiddenTopic"" MinimalFilter=""Off"" TopicFilter=""*H*T?pic*"" >
            <Channel Name=""SavedHiddenTopic"" MinimalFilter=""Release"" TopicFilter=""*DOSHOW*"" >
            </Channel>
        </Channel>
        <Channel Name=""MonitoredTopic"" MinimalFilter=""Monitor"" TopicFilter=""*MONITOR*"" >
        </Channel>
    </Channel>
</GrandOutputConfiguration>", LoadOptions.SetLineInfo).Root, TestHelper.ConsoleMonitor);

                Assert.That(g.SetConfiguration(config, TestHelper.ConsoleMonitor));

                var fullyHidden = new ActivityMonitor(false);
                g.Register(fullyHidden);
                fullyHidden.SetTopic("A fully hidden topic: setting the topic before any send, totally hides the monitor if the Actual filter is Off. - NOSHOW");
                fullyHidden.Fatal().Send("NOSHOW");
                using (fullyHidden.OpenFatal().Send("NOSHOW"))
                {
                    fullyHidden.Fatal().Send("NOSHOW");
                }

                var m = new ActivityMonitor(false);
                g.Register(m);
                m.Trace().Send("Trace-1");
                m.SetTopic("This is a Hidden Topic - NOSHOW");
                m.Fatal().Send("NOSHOW");
                m.SetTopic("Visible Topic");
                m.Trace().Send("Trace-2");
                m.SetTopic("This is a Hidden Topic but DOSHOW puts it in Release mode.");
                m.Trace().Send("NOSHOW");
                m.Info().Send("NOSHOW");
                m.Warn().Send("NOSHOW");
                m.Error().Send("Error-1");
                m.Fatal().Send("Fatal-1");
                m.SetTopic("This is a HT?PIC (off). Match is case insensitive - NOSHOW");
                m.Fatal().Send("NOSHOW");
                m.SetTopic(null);
                m.Trace().Send("Trace-3");
                m.SetTopic("A MONITORed topic: If i wrote This is a t.o.p.i.c (without the dots), this would have matched the HiddenT.o.p.i.c channel...");
                m.Trace().Send("NOSHOW");
                m.Warn().Send("Warn-1");
            }
            List <StupidStringClient> logs = TestHelper.ReadAllLogs(new DirectoryInfo(SystemActivityMonitor.RootLogPath + "FilteringByTopic"), false);

            Assert.That(logs.Count, Is.EqualTo(1), "Fully hidden monitor does not appear.");
            Assert.That(logs[0].ToString(), Does.Not.Contain("NOSHOW"));
            var texts = logs[0].Entries.Select(e => e.Text).ToArray();

            CollectionAssert.AreEqual(new string[] {
                "Trace-1",
                ActivityMonitor.SetTopicPrefix + "Visible Topic",
                "Trace-2",
                ActivityMonitor.SetTopicPrefix + "This is a Hidden Topic but DOSHOW puts it in Release mode.",
                "Error-1",
                "Fatal-1",
                ActivityMonitor.SetTopicPrefix,
                "Trace-3",
                ActivityMonitor.SetTopicPrefix + "A MONITORed topic: If i wrote This is a t.o.p.i.c (without the dots), this would have matched the HiddenT.o.p.i.c channel...",
                "Warn-1"
            }, texts, StringComparer.Ordinal);
        }