Example #1
0
        public static async Task <T> LogIfThrows <T>(this IFullLogger This, LogLevel level, string message, Func <Task <T> > block)
        {
            try {
                return(await block());
            } catch (Exception ex) {
                switch (level)
                {
                case LogLevel.Debug:
                    This.DebugException(message ?? "", ex);
                    break;

                case LogLevel.Info:
                    This.InfoException(message ?? "", ex);
                    break;

                case LogLevel.Warn:
                    This.WarnException(message ?? "", ex);
                    break;

                case LogLevel.Error:
                    This.ErrorException(message ?? "", ex);
                    break;
                }
                throw;
            }
        }
Example #2
0
        public static void LogIfThrows(this IFullLogger This, LogLevel level, string message, Action block)
        {
            try {
                block();
            } catch (Exception ex) {
                switch (level)
                {
                case LogLevel.Debug:
                    This.DebugException(message ?? "", ex);
                    break;

                case LogLevel.Info:
                    This.InfoException(message ?? "", ex);
                    break;

                case LogLevel.Warn:
                    This.WarnException(message ?? "", ex);
                    break;

                case LogLevel.Error:
                    This.ErrorException(message ?? "", ex);
                    break;
                }

                throw;
            }
        }
Example #3
0
 /// <summary>
 /// Sends the value provided by the provided delegate, only if Fatal is enabled.
 /// </summary>
 /// <param name="logger">The logger to use.</param>
 /// <param name="function">The function to evaluate if Fatal logging is enabled.</param>
 /// <param name="exception">A exception to log about.</param>
 public static void FatalException(this IFullLogger logger, Func <string> function, Exception exception)
 {
     if (logger.IsFatalEnabled)
     {
         logger.ErrorException(function.Invoke(), exception);
     }
 }
Example #4
0
        /// <summary>
        /// Sends the value provided by the provided delegate, only if Fatal is enabled.
        /// </summary>
        /// <param name="logger">The logger to use.</param>
        /// <param name="function">The function to evaluate if Fatal logging is enabled.</param>
        /// <param name="exception">A exception to log about.</param>
        public static void FatalException(this IFullLogger logger, Func <string> function, Exception exception)
        {
            if (logger.IsFatalEnabled)
            {
#pragma warning disable CS0618 // Type or member is obsolete
                logger.ErrorException(function.Invoke(), exception);
#pragma warning restore CS0618 // Type or member is obsolete
            }
        }
        /// <summary>
        /// Sends the value provided by the provided delegate, only if Error is enabled.
        /// </summary>
        /// <param name="logger">The logger to use.</param>
        /// <param name="function">The function to evaluate if Error logging is enabled.</param>
        /// <param name="exception">A exception to log about.</param>
        public static void ErrorException(this IFullLogger logger, Func <string> function, Exception exception)
        {
            if (logger is null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            if (function is null)
            {
                throw new ArgumentNullException(nameof(function));
            }

            if (logger.IsErrorEnabled)
            {
#pragma warning disable CS0618 // Type or member is obsolete
                logger.ErrorException(function.Invoke(), exception);
#pragma warning restore CS0618 // Type or member is obsolete
            }
        }