public void TestErrorForLoggable()
        {
            TestTarget.Current.Reset();

            // run...
            var loggable = new TestLoggable();
            loggable.LogError("Hello, world.");

            // check...
            Assert.AreEqual(1, TestTarget.Current.NumWritten);
            Assert.AreEqual(LogLevel.Error, TestTarget.Current.LastWritten.Level);
            Assert.IsNull(TestTarget.Current.LastWritten.Exception);
        }
Пример #2
0
        public void TestDebugForLoggableWithException()
        {
            TestTarget.Current.Reset();

            // run...
            var loggable = new TestLoggable();
            loggable.Debug("Hello, world", new InvalidOperationException("Foobar"));

            // check...
            Assert.AreEqual(1, TestTarget.Current.NumWritten);
            Assert.AreEqual(LogLevel.Debug, TestTarget.Current.LastWritten.Level);
            Assert.IsNotNull(TestTarget.Current.LastWritten.Exception);
        }
Пример #3
0
        public void TestDebugForLoggableWithFormat()
        {
            TestTarget.Current.Reset();

            // run...
            var loggable = new TestLoggable();
            loggable.Debug("Hello, {0}.", "**foo**");

            // check...
            Assert.AreEqual(1, TestTarget.Current.NumWritten);
            Assert.AreEqual(LogLevel.Debug, TestTarget.Current.LastWritten.Level);
            Assert.IsNull(TestTarget.Current.LastWritten.Exception);
            Assert.AreNotEqual(-1, TestTarget.Current.LastWritten.Message.IndexOf("**foo**"));
        }
Пример #4
0
        public async Task TestFileSnapshot()
        {
            LogManager.Reset();
            LogManager.DefaultConfiguration.ClearTargets();
            LogManager.DefaultConfiguration.AddTarget(LogLevel.Fatal, new FileSnapshotTarget());

            // send through a log entry...
            var loggable = new TestLoggable();
            var op = await loggable.Fatal("Testing file write...", new InvalidOperationException("An exception message..."));

            // load the file...
            var folder = await FileSnapshotTarget.EnsureInitializedAsync();
            var files = await folder.GetFilesAsync();
            var file = files.Where(v => v.Name.Contains(op[0].Entry.SequenceID.ToString())).First();
            string contents = await FileIO.ReadTextAsync(file);

            // check...
            Assert.IsTrue(contents.Contains("Testing file write..."));
            Assert.IsTrue(contents.Contains("An exception message..."));
        }
        public void TestFileSnapshot()
        {
            LogManager.Reset();
            LogManager.DefaultConfiguration.ClearTargets();
            LogManager.DefaultConfiguration.AddTarget(LogLevel.Fatal, new FileSnapshotTarget());

            // wait until the setup is finished...
            FileSnapshotTarget.BlockUntilSetup();

            // send through a log entry...
            var loggable = new TestLoggable();
            var entry = loggable.LogFatal("Testing file write...", new InvalidOperationException("An exception message..."));

            // wait until it's finished...
            entry.WaitUntilWritten();

            // get the file...
            var folder = FileSnapshotTarget.LogFolder;
            var filesTask = folder.GetFilesAsync().AsTask();
            filesTask.Wait();
            var files = filesTask.Result;
            var file = files.Where(v => v.Name.Contains(entry.SequenceID.ToString())).First();

            // get the contents...
            var streamTask = file.OpenStreamForWriteAsync();
            streamTask.Wait();
            string contents = null;
            using (var stream = streamTask.Result)
            {
                var reader = new StreamReader(stream);
                contents = reader.ReadToEnd();
            }

            // check...
            Assert.IsTrue(contents.Contains("Testing file write..."));
            Assert.IsTrue(contents.Contains("An exception message..."));
        }
Пример #6
0
        public void TestIsDebugEnabledForLoggable()
        {
            LogManager.Reset();
            LogManager.DefaultConfiguration.ClearTargets();
            LogManager.DefaultConfiguration.AddTarget(LogLevel.Info, LogLevel.Fatal, TestTarget.Current);

            // get a loggable...
            var loggable = new TestLoggable();

            // check...
            Assert.IsFalse(loggable.IsTraceEnabled());
            Assert.IsFalse(loggable.IsDebugEnabled());
            Assert.IsTrue(loggable.IsInfoEnabled());
            Assert.IsTrue(loggable.IsWarnEnabled());
            Assert.IsTrue(loggable.IsErrorEnabled());
            Assert.IsTrue(loggable.IsFatalEnabled());
        }