示例#1
0
        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));
            }
        }
示例#2
0
        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);
            }
        }
示例#3
0
        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);
            }
        }
示例#4
0
        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);
            }
        }
示例#5
0
        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);
            }
        }
示例#6
0
        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);
            }
        }
示例#7
0
        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);
            }
        }
示例#8
0
        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);
            }
        }
示例#9
0
        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);
            }
        }
示例#10
0
        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]);
            }
        }