Beispiel #1
0
            public void Debug(string message, params object[] args)
            {
                if (string.IsNullOrWhiteSpace(message))
                {
                    return;
                }

                _logger.Log(CSSMinifier.Logging.LogLevel.Debug, DateTime.Now, () => message, null);
            }
        /// <summary>
        /// This should throw an exception for a null message set but whether exceptions are thrown due to any other issues (eg. a message whose ContentGenerator
        /// delegate throws an exception or IO exceptions where file-writing is attempted) will vary depending upon the implementation
        /// </summary>
        public void Log(LogEventDetails message)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            if (!AllowedLogLevels.Contains(message.LogLevel))
            {
                return;
            }

            _logger.Log(message);
        }
Beispiel #3
0
        /// <summary>
        /// This should throw an exception for a null message set but whether exceptions are thrown due to any other issues (eg. a message whose ContentGenerator
        /// delegate throws an exception or IO exceptions where file-writing is attempted) will vary depending upon the implementation
        /// </summary>
        public void Log(LogEventDetails message)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            var messagesToLogImmediatelyIfAny = QueueMessageAndReturnAnyMessagesThatShouldBeLoggedImmediately(message);

            if ((messagesToLogImmediatelyIfAny != null) && (messagesToLogImmediatelyIfAny.Count > 0))
            {
                _logger.Log(messagesToLogImmediatelyIfAny);
            }
        }
 /// <summary>
 /// Wrap logging request in a try..catch and swallow any exception - this is an extension method that guarantees the exception will be caught, regardless
 /// of the logger implementation
 /// </summary>
 public static void LogIgnoringAnyError(this ILogEvents logger, LogLevel logLevel, Func <string> contentGenerator, Exception exception)
 {
     try
     {
         logger.Log(logLevel, DateTime.Now, contentGenerator, exception);
     }
     catch { }
 }
        public static void Log(this ILogEvents logger, LogLevel logLevel, DateTime logDate, int managedThreadId, Func <string> contentGenerator, Exception exception)
        {
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            logger.Log(new LogEventDetails(logLevel, logDate, managedThreadId, contentGenerator, exception));
        }
        /// <summary>
        /// Wrap logging request in a try..catch and swallow any exception - this is an extension method that guarantees the exception will be caught, regardless
        /// of the logger implementation
        /// </summary>
        public static void LogIgnoringAnyError(this ILogEvents logger, LogLevel logLevel, string content, Exception exception = null)
        {
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            try
            {
                logger.Log(new LogEventDetails(logLevel, DateTime.Now, Thread.CurrentThread.ManagedThreadId, content, exception));
            }
            catch { }
        }
        /// <summary>
        /// Wrap logging request in a try..catch and swallow any exception - this is an extension method that guarantees the exception will be caught, regardless
        /// of the logger implementation.
        /// </summary>
        public static void LogIgnoringAnyError(this ILogEvents logger, Exception error)
        {
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            // If there's no error then there's nothing to log, but this method is not supposed to throw an error when operating against a logger
            // implementation (which is why the ArgumentNullException above is acceptable) so if error is null then do nothing
            if (error == null)
            {
                return;
            }

            try
            {
                logger.Log(new LogEventDetails(LogLevel.Error, DateTime.Now, Thread.CurrentThread.ManagedThreadId, "", error));
            }
            catch { }
        }