public void ShouldTransgerLog() { using (var repository = new TemporaryFileSetUp()) { var logger = new JsonLoggerBuilder(repository.LogFilePath) .EnableFileSplitting(100, repository.SplittingFolder) .Build(); logger.Log("test"); string contentOfFile = repository.ReadAllText().Trim(); Assert.False(string.IsNullOrWhiteSpace(contentOfFile)); logger.Log("testing long message"); contentOfFile = repository.ReadAllText().Trim(); Assert.True(string.IsNullOrWhiteSpace(contentOfFile)); Assert.Single(Directory.EnumerateFiles(repository.SplittingFolder)); } }
public void LogArray() { using (var repo = new TemporaryFileSetUp()) { var logger = new JsonLoggerBuilder(repo.LogFilePath) .Build(); logger.Log(new string[] { "aaaa", "bbbbb", "ccccc" }); string contentOfFile = repo.ReadAllText().Trim(); AssertLogEntry("String[]", @"\[""aaaa"",""bbbbb"",""ccccc""\]", LogLevel.Info, DataType.Object, contentOfFile); } }
public void LogObject() { using (var repo = new TemporaryFileSetUp()) { var logger = new JsonLoggerBuilder(repo.LogFilePath) .Build(); logger.Log("test", new { p1 = 2, p2 = "text" }); string contentOfFile = repo.ReadAllText().Trim(); AssertLogEntry("test", "{\"p1\":2,\"p2\":\"text\"}", LogLevel.Info, DataType.Object, contentOfFile); } }
public void LogException() { using (var repo = new TemporaryFileSetUp()) { var logger = new JsonLoggerBuilder(repo.LogFilePath) .Build(); logger.Log("exception", new NullReferenceException("in exception")); string contentOfFile = repo.ReadAllText().Trim(); AssertLogEntry("exception", "\\{\"exceptionType\":\"System\\.NullReferenceException\",\"exception\":\\{\"message\":\"in exception\",\"data\":\\{\\},\"hResult\":-2147467261\\}\\}", LogLevel.Critical, DataType.Exception, contentOfFile); } }
public void CreateNewLogWithSingleEntry() { using (var repo = new TemporaryFileSetUp()) { var logger = new JsonLoggerBuilder(repo.LogFilePath) .Build(); logger.Warning("Test warning"); string contentOfFile = repo.ReadAllText() .Trim(); AssertLogEntry("Test warning", null, LogLevel.Warning, DataType.Text, contentOfFile); } }
public void LogBool() { using (var repo = new TemporaryFileSetUp()) { var logger = new JsonLoggerBuilder(repo.LogFilePath) .Build(); bool val = true; logger.Log(val); string contentOfFile = repo.ReadAllText().Trim(); AssertLogEntry("Boolean", "true", LogLevel.Info, DataType.Object, contentOfFile); } }
public void LogDouble() { using (var repo = new TemporaryFileSetUp()) { var logger = new JsonLoggerBuilder(repo.LogFilePath) .Build(); double val = 0.3; logger.Log(val); string contentOfFile = repo.ReadAllText().Trim(); AssertLogEntry("Double", "0.3", LogLevel.Info, DataType.Object, contentOfFile); } }
public void LogHiddenString() { using (var repo = new TemporaryFileSetUp()) { var logger = new JsonLoggerBuilder(repo.LogFilePath) .Build(); object hiddenString = "hello world"; logger.Log(hiddenString); string contentOfFile = repo.ReadAllText().Trim(); AssertLogEntry("String", "\"hello world\"", LogLevel.Info, DataType.Object, contentOfFile); } }
public void LogRecursive() { using (var repo = new TemporaryFileSetUp()) { var logger = new JsonLoggerBuilder(repo.LogFilePath) .Build(); var list = new List <object>(); list.Add(list); logger.Log(list); string contentOfFile = repo.ReadAllText().Trim(); Assert.Contains("List", contentOfFile); } }
public void CreateNewLogWithMessageAndExceptionEntries() { using (var repo = new TemporaryFileSetUp()) { var logger = new JsonLoggerBuilder(repo.LogFilePath) .Build(); logger.Log(new NullReferenceException()); logger.Warning("Test warning"); var contentOfFile = repo.ReadAllText() .Split('\n') .Select(str => str.Trim()) .ToArray(); Assert.Contains("NullReferenceException", contentOfFile[0]); AssertLogEntry("Test warning", null, LogLevel.Warning, DataType.Text, contentOfFile[1]); } }