Ejemplo n.º 1
0
        public void Warn_With_Generic_Type_Should_Emit_Message_And_Type_Provided()
        {
            string   passedMessage = null;
            LogLevel?passedLevel   = null;
            Type     passedType    = null;

            var logger = new ActionLogger(
                null,
                (message, type, level) =>
            {
                passedMessage = message;
                passedType    = type;
                passedLevel   = level;
            },
                null,
                null);

            var fullLogger = new WrappingFullLogger(logger);

            fullLogger.Warn <DummyObjectClass2>("This is a test.");

            Assert.Equal("This is a test.", passedMessage);
            Assert.Equal(LogLevel.Warn, passedLevel);
            Assert.Equal(typeof(DummyObjectClass2), passedType);
        }
        public void Warn_With_Generic_Type_Should_Write_Message_And_Type_Provided()
        {
            var textLogger = new TextLogger();
            var logger     = new WrappingFullLogger(new WrappingPrefixLogger(textLogger, typeof(DummyObjectClass1)));

            logger.Warn <DummyObjectClass2>("This is a test.");

            Assert.Equal($"{nameof(DummyObjectClass2)}: This is a test.", textLogger.Logs.Last().message.Trim(NewLine).Trim());
        }
Ejemplo n.º 3
0
        public void Warn_With_Generic_Type_Should_Write_Message_And_Type()
        {
            var textLogger = new TextLogger();
            var logger     = new WrappingFullLogger(new WrappingPrefixLogger(textLogger, typeof(DummyObjectClass1)));

            logger.Warn <DummyObjectClass1>("This is a test.");

            Assert.Equal($"{nameof(DummyObjectClass1)}: This is a test.\r\n", textLogger.Value);
        }
Ejemplo n.º 4
0
        public void Warn_With_Generic_Type_Should_Write_Message_And_Type_Provided()
        {
            var textLogger = new TextLogger();
            var logger     = new WrappingFullLogger(textLogger);

            logger.Warn <DummyObjectClass2>("This is a test.");

            Assert.Equal("This is a test.\r\n", textLogger.Value);
            Assert.Equal(typeof(DummyObjectClass2), textLogger.PassedTypes.FirstOrDefault());
        }
Ejemplo n.º 5
0
        public void Warn_With_Generic_Type_Should_Write_Message_And_Type_Provided()
        {
            var nlogLoggerAndMemoryTarget = GetSplatNLogLoggerAndMemoryTarget();
            var logger       = new WrappingFullLogger(nlogLoggerAndMemoryTarget.Logger);
            var memoryTarget = nlogLoggerAndMemoryTarget.MemoryTarget;

            Assert.Equal(0, memoryTarget.Logs.Count);

            logger.Warn <DummyObjectClass2>("This is a test.");

            Assert.Equal(1, memoryTarget.Logs.Count);
            Assert.Equal($"{nameof(DummyObjectClass2)}: This is a test.", memoryTarget.Logs.First());
        }
Ejemplo n.º 6
0
        public void Warn_With_Generic_Type_Should_Write_Message_And_Type_Provided()
        {
            var serilogLoggerAndTarget = GetSplatSerilogLoggerAndTarget();
            var logger = new WrappingFullLogger(serilogLoggerAndTarget.Logger);
            var target = serilogLoggerAndTarget.Target;

            Assert.Equal(0, target.Logs.Count);

            logger.Warn <DummyObjectClass2>("This is a test.");

            Assert.Equal(1, target.Logs.Count);
            Assert.Equal($"{typeof(DummyObjectClass2).FullName}: This is a test.", target.Logs.First());
        }
Ejemplo n.º 7
0
        public void Warn_With_Generic_Type_Should_Write_Message_And_Type_Provided()
        {
            var loggerAndInMemoryOutput = GetSplatLoggerAndMemoryTarget();
            var logger       = new WrappingFullLogger(loggerAndInMemoryOutput.Logger);
            var memoryTarget = loggerAndInMemoryOutput.MemoryTarget;

            Assert.Empty(memoryTarget.GetEvents());

            logger.Warn <DummyObjectClass2>("This is a test.");

            var logEvent = Assert.Single(memoryTarget.GetEvents());

            Assert.Equal($"{nameof(DummyObjectClass2)}: This is a test.", logEvent.MessageObject);
        }
Ejemplo n.º 8
0
        public void Warn_Enabled_Should_Emit()
        {
            var  textLogger = new TextLogger();
            bool invoked    = false;
            var  logger     = new WrappingFullLogger(textLogger);

            logger.Level = LogLevel.Debug;

            logger.Warn <DummyObjectClass1>(
                () =>
            {
                invoked = true;
                return("This is a test.");
            });

            Assert.Equal("This is a test.\r\n", textLogger.Value);
            Assert.Equal(typeof(DummyObjectClass1), textLogger.PassedTypes.FirstOrDefault());
            Assert.True(invoked);
        }
Ejemplo n.º 9
0
        public void Warn_Disabled_Should_Not_Emit()
        {
            var textLogger = new TextLogger();
            var logger     = new WrappingFullLogger(textLogger);
            var invoked    = false;

            logger.Level = LogLevel.Fatal;

            logger.Warn <DummyObjectClass1>(
                () =>
            {
                invoked = true;
                return("This is a test.");
            });

            Assert.Null(textLogger.Value);
            Assert.Null(textLogger.PassedTypes.FirstOrDefault());
            Assert.False(invoked);
        }