Ejemplo n.º 1
0
        [TestMethod()] public void LoggerProxy()
        {
            Log.WriteDelay = 1000;
            var         Log2  = new FileLogger("logtest2.tmp", 1000);
            LoggerProxy proxy = new LoggerProxy(true, Log);

            proxy.Masters.Add(Log2);

            proxy.Info("Proxy");
            proxy.Flush();
            Assert.IsTrue(LogContent.Contains("Proxy"), "Proxy is forwarding to 1st log");
            Assert.IsTrue(File.ReadAllText(Log2.LogFile).Contains("Proxy"), "Proxy is forwarding to 2nd log");

            proxy.Clear();
            Assert.IsFalse(File.Exists(Log.LogFile), "Proxy is clearing 1st Log");
            Assert.IsFalse(File.Exists(Log2.LogFile), "Proxy is clearing 2nd Log");

            Log2.Level  = System.Diagnostics.SourceLevels.Verbose;
            proxy.Level = System.Diagnostics.SourceLevels.Information;
            proxy.Verbo("Verbose filtered");
            proxy.Flush();
            Assert.IsFalse(File.Exists(Log.LogFile), "Proxy is not forwarding low levels");
            Assert.IsFalse(File.Exists(Log2.LogFile), "Proxy is not forwarding low levels 2");

            proxy.Level = System.Diagnostics.SourceLevels.Verbose;
            proxy.Verbo("Verbose written");
            proxy.Flush();
            Assert.IsFalse(File.Exists(Log.LogFile), "Proxy is not writing to low levels");
            Assert.IsTrue(File.Exists(Log2.LogFile), "Proxy is writing to low levels 2");
            proxy.Clear();

            try {
                new LoggerProxy(false).Clear();
                Assert.IsTrue(false, "Proxy failed to disallow clear");
            } catch (InvalidOperationException) {
                Assert.IsTrue(true, "Proxy may disallow clear");
            }

            Assert.AreEqual(null, Error, "OnError");
        }