Пример #1
0
 public override void StartTest()
 {
     base.StartTest();
     _app = Log.AppStart("Test Start");
     NextMessage.ToString();
     NextMessage.ToString();
 }
        public override void Setup()
        {
            base.Setup();

            _out   = Console.Out;
            _error = Console.Error;
            Console.SetOut(_rout     = new StringWriter());
            Console.SetError(_rerror = new StringWriter());

            Log.LogWrite += new LogEventHandler(Log_LogWrite);

            if (Log.Config.Level != LogLevels.Verbose)
            {
                Log.Config.Level = LogLevels.Verbose;
            }

            // To ensure that the log is functioning properly we will set ALL output devices (save for EventLog since we don't have a well-known source)
            Log.Config.Output = LogOutputs.AspNetTrace | LogOutputs.Console | LogOutputs.LogFile | LogOutputs.TraceWrite;
            NextMessage.ToString();
            Log.Config.Options = LogOptions.GZipLogFileOnRoll | LogOptions.ConsoleColors | LogOptions.LogAddAssemblyInfo | LogOptions.LogAddFileInfo | LogOptions.LogImmediateCaller | LogOptions.LogNearestCaller;
            NextMessage.ToString();
            Log.Config.Level = LogLevels.Verbose;
            NextMessage.ToString();
            Log.Config.SetOutputFormat(LogOutputs.TraceWrite, "{Message}");
            NextMessage.ToString();
        }
        public void TestWriteThrough()
        {
            Log.Config.Level = LogLevels.None;
            NextMessage.ToString();
            Assert.IsFalse(Log.IsVerboseEnabled);
            Assert.IsFalse(Log.IsInfoEnabled);

            _lastTrace = null;
            _lastMessages.Clear();

            Log.Critical("Test All off");
            Assert.IsNull(_lastTrace);
            Assert.AreEqual(0, _lastMessages.Count);

            Log.Write("Test PassThrough?");
            EventData data = LastMessage;

            Assert.AreEqual("Test PassThrough?", data.Message);
        }
        public void TestIsEnabled()
        {
            Assert.IsTrue(Log.IsVerboseEnabled);
            Assert.IsTrue(Log.IsInfoEnabled);

            Log.Config.Level = LogLevels.Info;
            NextMessage.ToString();
            Assert.IsFalse(Log.IsVerboseEnabled);
            Assert.IsTrue(Log.IsInfoEnabled);

            _lastTrace = null;
            _lastMessages.Clear();

            Log.Verbose("Test Verbose off");
            Assert.IsNull(_lastTrace);
            Assert.AreEqual(0, _lastMessages.Count);

            Log.Config.Level = LogLevels.Warning;
            Assert.IsFalse(Log.IsInfoEnabled);

            Log.Verbose("Test Info off");
            Assert.IsNull(_lastTrace);
            Assert.AreEqual(0, _lastMessages.Count);

            Log.Config.Level = LogLevels.None;
            Assert.IsFalse(Log.IsInfoEnabled);
            Assert.IsFalse(Log.IsVerboseEnabled);

            Log.Critical("Test All off");
            Assert.IsNull(_lastTrace);
            Assert.AreEqual(0, _lastMessages.Count);

            Log.Write("Test PassThrough?");
            Assert.AreEqual("Test PassThrough?", LastMessage.Message);

            Log.Config.Level = LogLevels.Verbose;
            Assert.IsTrue(Log.IsVerboseEnabled);
            Assert.IsTrue(Log.IsInfoEnabled);
        }