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...")); }
public void TestFatalForLoggable() { TestTarget.Current.Reset(); // run... var loggable = new TestLoggable(); loggable.LogFatal("Hello, world."); // check... Assert.AreEqual(1, TestTarget.Current.NumWritten); Assert.AreEqual(LogLevel.Fatal, TestTarget.Current.LastWritten.Level); Assert.IsNull(TestTarget.Current.LastWritten.Exception); }
public void TestFatalForLoggableWithFormat() { TestTarget.Current.Reset(); // run... var loggable = new TestLoggable(); loggable.LogFatal("Hello, {0}.", "**foo**"); // check... Assert.AreEqual(1, TestTarget.Current.NumWritten); Assert.AreEqual(LogLevel.Fatal, TestTarget.Current.LastWritten.Level); Assert.IsNull(TestTarget.Current.LastWritten.Exception); Assert.AreNotEqual(-1, TestTarget.Current.LastWritten.Message.IndexOf("**foo**")); }
public void TestFatalForLoggableWithException() { TestTarget.Current.Reset(); // run... var loggable = new TestLoggable(); loggable.LogFatal("Hello, world", new InvalidOperationException("Foobar")); // check... Assert.AreEqual(1, TestTarget.Current.NumWritten); Assert.AreEqual(LogLevel.Fatal, TestTarget.Current.LastWritten.Level); Assert.IsNotNull(TestTarget.Current.LastWritten.Exception); }