public bool Log(MvxLogLevel logLevel, Func <string> messageFunc, Exception exception,
                            params object[] formatParameters)
            {
                if (messageFunc == null)
                {
                    return(true);
                }

                messageFunc = LogMessageFormatter.SimulateStructuredLogging(messageFunc, formatParameters);

                Write(logLevel, messageFunc(), exception);
                return(true);
            }
            public bool Log(MvxLogLevel logLevel, Func <string> messageFunc, Exception exception, params object[] formatParameters)
            {
                if (messageFunc == null)
                {
                    //nothing to log..
                    return(true);
                }

                messageFunc = LogMessageFormatter.SimulateStructuredLogging(messageFunc, formatParameters);

                _logWriteDelegate((int)ToLogMessageSeverity(logLevel), LogSystem, _skipLevel, exception, true, 0, null,
                                  _category, null, messageFunc.Invoke());

                return(true);
            }
            public bool Log(MvxLogLevel logLevel, Func <string> messageFunc, Exception exception, params object[] formatParameters)
            {
                var severity = MapSeverity(logLevel);

                if (messageFunc == null)
                {
                    return(_shouldLog(_loggerName, severity));
                }

                messageFunc = LogMessageFormatter.SimulateStructuredLogging(messageFunc, formatParameters);
                if (exception != null)
                {
                    return(LogException(logLevel, messageFunc, exception));
                }

                _writeLog(_loggerName, messageFunc(), severity);
                return(true);
            }
예제 #4
0
            public bool Log(MvxLogLevel logLevel, Func <string> messageFunc, Exception exception, params object[] formatParameters)
            {
                if (messageFunc == null)
                {
                    return(IsLogLevelEnable(logLevel));
                }

                if (!IsLogLevelEnable(logLevel))
                {
                    return(false);
                }

                string message = messageFunc();

                IEnumerable <string> patternMatches;

                string formattedMessage =
                    LogMessageFormatter.FormatStructuredMessage(message,
                                                                formatParameters,
                                                                out patternMatches);

                // determine correct caller - this might change due to jit optimizations with method inlining
                if (s_callerStackBoundaryType == null)
                {
                    lock (CallerStackBoundaryTypeSync)
                        s_callerStackBoundaryType = typeof(MvxLog);
                }

                var translatedLevel = TranslateLevel(logLevel);

                object loggingEvent = _createLoggingEvent(_logger, s_callerStackBoundaryType, translatedLevel, formattedMessage, exception);

                PopulateProperties(loggingEvent, patternMatches, formatParameters);

                _logDelegate(_logger, loggingEvent);

                return(true);
            }
            public bool Log(MvxLogLevel logLevel, Func <string> messageFunc, Exception exception, params object[] formatParameters)
            {
                if (messageFunc == null)
                {
                    return(IsLogLevelEnable(logLevel));
                }
                messageFunc = LogMessageFormatter.SimulateStructuredLogging(messageFunc, formatParameters);

                if (_logEventInfoFact != null)
                {
                    if (IsLogLevelEnable(logLevel))
                    {
                        var nlogLevel = TranslateLevel(logLevel);
                        _logger.Log(_logEventInfoFact(_logger.Name, nlogLevel, messageFunc(), exception));
                        return(true);
                    }
                    return(false);
                }

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

                case MvxLogLevel.Info:
                    if (_logger.IsInfoEnabled)
                    {
                        _logger.Info(messageFunc());
                        return(true);
                    }
                    break;

                case MvxLogLevel.Warn:
                    if (_logger.IsWarnEnabled)
                    {
                        _logger.Warn(messageFunc());
                        return(true);
                    }
                    break;

                case MvxLogLevel.Error:
                    if (_logger.IsErrorEnabled)
                    {
                        _logger.Error(messageFunc());
                        return(true);
                    }
                    break;

                case MvxLogLevel.Fatal:
                    if (_logger.IsFatalEnabled)
                    {
                        _logger.Fatal(messageFunc());
                        return(true);
                    }
                    break;

                default:
                    if (_logger.IsTraceEnabled)
                    {
                        _logger.Trace(messageFunc());
                        return(true);
                    }
                    break;
                }
                return(false);
            }
예제 #6
0
            public bool Log(MvxLogLevel logLevel, Func <string> messageFunc, Exception exception, params object[] formatParameters)
            {
                if (messageFunc == null)
                {
                    return(IsLogLevelEnable(logLevel));
                }

                if (_logEventInfoFact != null)
                {
                    if (IsLogLevelEnable(logLevel))
                    {
                        var formatMessage = messageFunc();
                        if (!_structuredLoggingEnabled)
                        {
                            IEnumerable <string> _;
                            formatMessage =
                                LogMessageFormatter.FormatStructuredMessage(formatMessage,
                                                                            formatParameters,
                                                                            out _);
                            formatParameters = null; // Has been formatted, no need for parameters
                        }

                        var nlogLevel = TranslateLevel(logLevel);
                        var nlogEvent = _logEventInfoFact(_loggerNameDelegate(_logger), nlogLevel, formatMessage, formatParameters, exception);
                        _logEventDelegate(_logger, typeof(IMvxLog), nlogEvent);
                        return(true);
                    }

                    return(false);
                }

                messageFunc = LogMessageFormatter.SimulateStructuredLogging(messageFunc, formatParameters);
                if (exception != null)
                {
                    return(LogException(logLevel, messageFunc, exception));
                }
                switch (logLevel)
                {
                case MvxLogLevel.Debug:
                    if (_isDebugEnabledDelegate(_logger))
                    {
                        _debugDelegate(_logger, messageFunc());
                        return(true);
                    }

                    break;

                case MvxLogLevel.Info:
                    if (_isInfoEnabledDelegate(_logger))
                    {
                        _infoDelegate(_logger, messageFunc());
                        return(true);
                    }

                    break;

                case MvxLogLevel.Warn:
                    if (_isWarnEnabledDelegate(_logger))
                    {
                        _warnDelegate(_logger, messageFunc());
                        return(true);
                    }

                    break;

                case MvxLogLevel.Error:
                    if (_isErrorEnabledDelegate(_logger))
                    {
                        _errorDelegate(_logger, messageFunc());
                        return(true);
                    }

                    break;

                case MvxLogLevel.Fatal:
                    if (_isFatalEnabledDelegate(_logger))
                    {
                        _fatalDelegate(_logger, messageFunc());
                        return(true);
                    }

                    break;

                default:
                    if (_isTraceEnabledDelegate(_logger))
                    {
                        _traceDelegate(_logger, messageFunc());
                        return(true);
                    }

                    break;
                }

                return(false);
            }