Example #1
0
            private bool LogException(LogLevel logLevel, Func <string> messageFunc, Exception exception)
            {
                switch (logLevel)
                {
                case LogLevel.Debug:
                    if (logger.IsDebugEnabled)
                    {
                        logger.Debug(exception, messageFunc());
                        return(true);
                    }
                    break;

                case LogLevel.Info:
                    if (logger.IsInfoEnabled)
                    {
                        logger.Info(exception, messageFunc());
                        return(true);
                    }
                    break;

                case LogLevel.Warn:
                    if (logger.IsWarnEnabled)
                    {
                        logger.Warn(exception, messageFunc());
                        return(true);
                    }
                    break;

                case LogLevel.Error:
                    if (logger.IsErrorEnabled)
                    {
                        logger.Error(exception, messageFunc());
                        return(true);
                    }
                    break;

                case LogLevel.Fatal:
                    if (logger.IsFatalEnabled)
                    {
                        logger.Fatal(exception, messageFunc());
                        return(true);
                    }
                    break;

                default:
                    if (logger.IsTraceEnabled)
                    {
                        logger.Trace(exception, messageFunc());
                        return(true);
                    }
                    break;
                }
                return(false);
            }
Example #2
0
            private bool IsLogLevelEnable(LogLevel logLevel)
            {
                switch (logLevel)
                {
                case LogLevel.Debug:
                    return(logger.IsDebugEnabled);

                case LogLevel.Info:
                    return(logger.IsInfoEnabled);

                case LogLevel.Warn:
                    return(logger.IsWarnEnabled);

                case LogLevel.Error:
                    return(logger.IsErrorEnabled);

                case LogLevel.Fatal:
                    return(logger.IsFatalEnabled);

                default:
                    return(logger.IsTraceEnabled);
                }
            }
Example #3
0
            public bool Log(LogLevel logLevel, Func <string> messageFunc, Exception exception, params object[] formatParameters)
            {
                if (messageFunc == null)
                {
                    return(IsLogLevelEnable(logLevel));
                }
                messageFunc = LogMessageFormatter.SimulateStructuredLogging(messageFunc, formatParameters);

                if (exception != null)
                {
                    return(LogException(logLevel, messageFunc, exception));
                }
                switch (logLevel)
                {
                case LogLevel.Debug:
                    if (logger.IsDebugEnabled)
                    {
                        logger.Debug(messageFunc());
                        return(true);
                    }
                    break;

                case LogLevel.Info:
                    if (logger.IsInfoEnabled)
                    {
                        logger.Info(messageFunc());
                        return(true);
                    }
                    break;

                case LogLevel.Warn:
                    if (logger.IsWarnEnabled)
                    {
                        logger.Warn(messageFunc());
                        return(true);
                    }
                    break;

                case LogLevel.Error:
                    if (logger.IsErrorEnabled)
                    {
                        logger.Error(messageFunc());
                        return(true);
                    }
                    break;

                case LogLevel.Fatal:
                    if (logger.IsFatalEnabled)
                    {
                        logger.Fatal(messageFunc());
                        return(true);
                    }
                    break;

                default:
                    if (logger.IsTraceEnabled)
                    {
                        logger.Trace(messageFunc());
                        return(true);
                    }
                    break;
                }
                return(false);
            }