示例#1
0
        public void Configuring_With_Static_Log_Should_Write_Message()
        {
            var originalLocator = Locator.InternalLocator;

            try
            {
                Locator.InternalLocator = new InternalLocator();
                var(seriLogger, target) = CreateSerilogger(LogLevel.Debug);
                Log.Logger = seriLogger;

                Locator.CurrentMutable.UseSerilogFullLogger();

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

                IEnableLogger logger = null;
                logger.Log().Debug <DummyObjectClass2>("This is a test.");

                Assert.Equal(1, target.Logs.Count);
                Assert.Equal("This is a test.", target.Logs.Last().message.Trim(NewLine).Trim());
            }
            finally
            {
                Locator.InternalLocator = originalLocator;
            }
        }
示例#2
0
        public void Configuring_With_PreConfigured_Log_Should_Write_Message()
        {
            var serilogLoggerAndTarget = GetActualSerilogLoggerAndTarget();
            var target = serilogLoggerAndTarget.Target;

            Locator.CurrentMutable.UseSerilogFullLogger(serilogLoggerAndTarget.Logger);

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

            IEnableLogger logger = null;

            // Will Fail
            logger.Log().Debug <DummyObjectClass2>("This is a test.");

            Assert.Equal(1, target.Logs.Count);
            Assert.Equal($"{typeof(DummyObjectClass2).FullName}: This is a test.", target.Logs.First());
        }
示例#3
0
 public static Task <T> ErrorIfThrows <T>(this IEnableLogger This, Func <Task <T> > block, string message = null)
 {
     return(This.Log().LogIfThrows(LogLevel.Error, message, block));
 }
示例#4
0
 public static void ErrorIfThrows(this IEnableLogger This, Action block, string message = null)
 {
     This.Log().LogIfThrows(LogLevel.Error, message, block);
 }
示例#5
0
 public static Task WarnIfThrows(this IEnableLogger This, Func <Task> block, string message = null)
 {
     return(This.Log().LogIfThrows(LogLevel.Warn, message, block));
 }