Example #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;
            }
        }
Example #2
0
        public static IFullLogger Log(this IEnableLogger logger)
        {
            ILogManager service = Locator.Current.GetService <ILogManager>();

            if (service == null)
            {
                throw new Exception("ILogManager is null. This should never happen, your dependency resolver is broken");
            }
            return(service.GetLogger(logger.GetType()));
        }
Example #3
0
        /// <summary>
        /// Log returns the current logger object, which allows the object to
        /// log messages with the type name attached.
        /// </summary>
        /// <returns></returns>
        public static ILog Log(this IEnableLogger This)
        {
            // Prevent recursive meta-logging
            if (This is MemoizingMRUCache <int, ILog> )
            {
                return(mruLogger);
            }

            lock (loggerCache) {
                return(loggerCache.Get(This.GetHashCode(), This));
            }
        }
Example #4
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());
        }
Example #5
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));
 }
Example #6
0
 public static void ErrorIfThrows(this IEnableLogger This, Action block, string message = null)
 {
     This.Log().LogIfThrows(LogLevel.Error, message, block);
 }
Example #7
0
 public static Task WarnIfThrows(this IEnableLogger This, Func <Task> block, string message = null)
 {
     return(This.Log().LogIfThrows(LogLevel.Warn, message, block));
 }
Example #8
0
 public static void LogFatal(this IEnableLogger _, Exception exception)
 => _logger.LogFatal(exception);
Example #9
0
 public static void LogFatal(this IEnableLogger _, object classifier, Exception exception)
 => _logger.LogFatal(classifier, exception);
Example #10
0
 public static void LogFatal(this IEnableLogger _, object classifier, Exception exception, string message)
 => _logger.LogFatal(classifier, exception, message);
Example #11
0
 public static void LogError(this IEnableLogger _, Exception exception)
 => _logger.LogError(exception);
Example #12
0
 public static void LogWarning(this IEnableLogger _, string message)
 => _logger.LogWarning(message);
Example #13
0
 public static void LogWarning(this IEnableLogger _, object classifier, string message)
 => _logger.LogWarning(classifier, message);
Example #14
0
 public static void LogInformation(this IEnableLogger _, string message)
 => _logger.LogInformation(message);
Example #15
0
 public static void LogInformation(this IEnableLogger _, object classifier, string message)
 => _logger.LogInformation(classifier, message);