Пример #1
0
        public void should_use_serilog_silent_logger()
        {
            var factory = new SerilogFactory();
            var logger = factory.Create("TestingLogger");

            WriteTestLogs(logger);
        }
Пример #2
0
        public void should_log_work_with_second_creator()
        {
            var output = new StringWriter();

            var config = new LoggerConfiguration()
                .MinimumLevel.Is(LogEventLevel.Debug)
                .WriteTo.TextWriter(output);

            var factory = new SerilogFactory(config);
            var logger = factory.Create("TestingLogger");

            WriteTestLogs(logger);

            var logs = output.ToString();

            StringAssert.Contains("Testing debug", logs);
            StringAssert.Contains("Testing warning", logs);
        }
Пример #3
0
        public void should_not_log_debug_with_new_serilog_config()
        {
            var output = new StringWriter();

            // New LoggerConfiguration which defaults to Information
            var config = new LoggerConfiguration()
                .WriteTo.TextWriter(output);

            var factory = new SerilogFactory(config);
            var logger = factory.Create("TestingLogger");

            WriteTestLogs(logger);

            var logs = output.ToString();

            StringAssert.DoesNotContain("Testing debug", logs);
            StringAssert.Contains("Testing info", logs);
            StringAssert.Contains("Testing warning", logs);
        }
Пример #4
0
 public SerilogLogger(ILogger logger, SerilogFactory factory)
 {
     Logger  = logger;
     Factory = factory;
 }
Пример #5
0
 public SerilogLogger(ILogger logger, SerilogFactory factory)
 {
     Logger = logger;
     Factory = factory;
 }
Пример #6
0
        public void should_log_with_source_context()
        {
            var output = new StringWriter();
            var serilogLogger = new LoggerConfiguration()
                .MinimumLevel.Debug()
                .WriteTo.TextWriter(output)
                .CreateLogger();

            var factory = new SerilogFactory(serilogLogger);

            var logger1 = factory.Create("MyLogger1");
            var logger2 = factory.Create("MyLogger2");

            logger1.Info("Test1 using {SourceContext}");
            logger2.Debug("Test2 using {SourceContext}");

            var logs = output.ToString();
            StringAssert.Contains("MyLogger1", logs);
            StringAssert.Contains("MyLogger2", logs);
        }
Пример #7
0
        public void should_log_exceptions()
        {
            var output = new StringWriter();

            var serilogLogger = new LoggerConfiguration()
                .MinimumLevel.Debug()
                .WriteTo.TextWriter(output)
                .CreateLogger();

            var factory = new SerilogFactory(serilogLogger);
            var logger = factory.Create("TestingLogger");

            logger.Debug("Debug", new Exception("Debug Exception 1"));
            logger.DebugFormat(new Exception("Debug Exception 2"), "Debug");
            logger.DebugFormat(new Exception("Debug Exception 3"), null, "Debug");
            logger.Error("Error", new Exception("Error Exception 1"));
            logger.ErrorFormat(new Exception("Error Exception 2"), "Error");
            logger.ErrorFormat(new Exception("Error Exception 3"), null, "Error");
            logger.Fatal("Fatal", new Exception("Fatal Exception 1"));
            logger.FatalFormat(new Exception("Fatal Exception 2"), "Fatal");
            logger.FatalFormat(new Exception("Fatal Exception 3"), null, "Fatal");
            logger.Info("Info", new Exception("Info Exception 1"));
            logger.InfoFormat(new Exception("Info Exception 2"), "Info");
            logger.InfoFormat(new Exception("Info Exception 3"), null, "Info");
            logger.Warn("Warn", new Exception("Warn Exception 1"));
            logger.WarnFormat(new Exception("Warn Exception 2"), "Warn");
            logger.WarnFormat(new Exception("Warn Exception 3"), null, "Warn");

            var logs = output.ToString();
            StringAssert.Contains("Debug Exception 1", logs);
            StringAssert.Contains("Debug Exception 2", logs);
            StringAssert.Contains("Debug Exception 3", logs);
            StringAssert.Contains("Error Exception 1", logs);
            StringAssert.Contains("Error Exception 2", logs);
            StringAssert.Contains("Error Exception 3", logs);
            StringAssert.Contains("Fatal Exception 1", logs);
            StringAssert.Contains("Fatal Exception 2", logs);
            StringAssert.Contains("Fatal Exception 3", logs);
            StringAssert.Contains("Info Exception 1", logs);
            StringAssert.Contains("Info Exception 2", logs);
            StringAssert.Contains("Info Exception 3", logs);
            StringAssert.Contains("Warn Exception 1", logs);
            StringAssert.Contains("Warn Exception 2", logs);
            StringAssert.Contains("Warn Exception 3", logs);
        }
Пример #8
0
        public void should_log_objects()
        {
            var output = new StringWriter();

            var serilogLogger = new LoggerConfiguration()
                .MinimumLevel.Debug()
                .WriteTo.TextWriter(output)
                .CreateLogger();

            var factory = new SerilogFactory(serilogLogger);
            var logger = factory.Create("TestingLogger");

            logger.DebugFormat("Testing Debug {@TestingData}", new { Name = "test", Value = 55 });

            var logs = output.ToString();

            StringAssert.Contains("{ Name: \"test\", Value: 55 }", logs);
        }