Beispiel #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;
            }
        }
Beispiel #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;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Sends the value provided by the provided delegate, only if Debug is enabled.
        /// </summary>
        /// <param name="logger">The logger to use.</param>
        /// <param name="function">The function to evaluate if Debug logging is enabled.</param>
        /// <param name="exception">A exception to log about.</param>
        public static void DebugException(this IFullLogger logger, Func <string> function, Exception exception)
        {
            if (logger.IsDebugEnabled)
            {
#pragma warning disable CS0618 // Type or member is obsolete
                logger.DebugException(function.Invoke(), exception);
#pragma warning restore CS0618 // Type or member is obsolete
            }
        }
        /// <summary>
        /// Sends the value provided by the provided delegate, only if Debug is enabled.
        /// </summary>
        /// <param name="logger">The logger to use.</param>
        /// <param name="function">The function to evaluate if Debug logging is enabled.</param>
        /// <param name="exception">A exception to log about.</param>
        public static void DebugException(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.IsDebugEnabled)
            {
#pragma warning disable CS0618 // Type or member is obsolete
                logger.DebugException(function.Invoke(), exception);
#pragma warning restore CS0618 // Type or member is obsolete
            }
        }