Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the TRexIgniteLogger class with the provided ILog interface
        /// </summary>
        /// <param name="logger"></param>
        public TRexIgniteLogger(IConfigurationStore configStore, Microsoft.Extensions.Logging.ILogger logger)
        {
            _logger = logger;
            var level = configStore.GetValueInt("TREX_IGNITE_MIN_LOG_LEVEL", (int)LogLevel.Info);

            if (level < (int)LogLevel.Trace || level > (int)LogLevel.Error)
            {
                _logger.LogWarning($"Invalid log level {level} provided. Must be between {(int)LogLevel.Trace} ({LogLevel.Trace}) and {(int)LogLevel.Error} ({LogLevel.Error}). Defaulting to {LogLevel.Info}");
                _minLogLevel = LogLevel.Info;
            }
            else
            {
                _minLogLevel = (LogLevel)level;
            }

            _logger.LogInformation($"Minimum log level for Ignite: {_minLogLevel}");
        }
Beispiel #2
0
        /// <summary>
        /// Logs the specified message.
        /// </summary>
        /// <param name="level">The level.</param>
        /// <param name="message">The message.</param>
        /// <param name="args">The arguments to format <paramref name="message" />.
        /// Can be null (formatting will not occur).</param>
        /// <param name="formatProvider">The format provider. Can be null if <paramref name="args" /> is null.</param>
        /// <param name="category">The logging category name.</param>
        /// <param name="nativeErrorInfo">The native error information.</param>
        /// <param name="ex">The exception. Can be null.</param>
        /// <exception cref="System.NotImplementedException"></exception>
        public void Log(IgniteLogLevel level, string message, object[] args, IFormatProvider formatProvider, 
            string category, string nativeErrorInfo, Exception ex)
        {
            var logEvent = new LogEventInfo
            {
                Level = ConvertLogLevel(level),
                Message = message,
                FormatProvider = formatProvider,
                Parameters = args,
                Exception = ex,
                LoggerName = category
            };

            if (nativeErrorInfo != null)
                logEvent.Properties.Add("nativeErrorInfo", nativeErrorInfo);

            _logger.Log(logEvent);
        }
Beispiel #3
0
        /// <summary>Logs the specified message.</summary>
        /// <param name="level">The level.</param>
        /// <param name="message">The message.</param>
        /// <param name="args">The arguments to format <paramref name="message" />.
        /// Can be null (formatting will not occur).</param>
        /// <param name="formatProvider">The format provider. Can be null if <paramref name="args" /> is null.</param>
        /// <param name="category">The logging category name.</param>
        /// <param name="nativeErrorInfo">The native error information.</param>
        /// <param name="ex">The exception. Can be null.</param>
        public void Log(LogLevel level, string message, object[] args, IFormatProvider formatProvider, string category,
                        string nativeErrorInfo, Exception ex)
        {
            object obj = args == null ? message : null;

            _logger.Log <object>(ConvertLogLevel2(level), new EventId(0, ""), obj, ex,
                                 (_state, _ex) => ex != null ? $"{_state}, Exception {_ex}" : $"{_state}");

            /*
             *  /// <summary>Writes a log entry.</summary>
             *  /// <param name="logLevel">Entry will be written on this level.</param>
             *  /// <param name="eventId">Id of the event.</param>
             *  /// <param name="state">The entry to be written. Can be also an object.</param>
             *  /// <param name="exception">The exception related to this entry.</param>
             *  /// <param name="formatter">Function to create a <c>string</c> message of the <paramref name="state" /> and <paramref name="exception" />.</param>
             *  void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter);
             */
        }
        /// <summary>
        /// Logs the specified message.
        /// </summary>
        /// <param name="level">The level.</param>
        /// <param name="message">The message.</param>
        /// <param name="args">The arguments to format <paramref name="message" />.
        /// Can be null (formatting will not occur).</param>
        /// <param name="formatProvider">The format provider. Can be null if <paramref name="args" /> is null.</param>
        /// <param name="category">The logging category name.</param>
        /// <param name="nativeErrorInfo">The native error information.</param>
        /// <param name="ex">The exception. Can be null.</param>
        /// <exception cref="System.NotImplementedException"></exception>
        public void Log(IgniteLogLevel level, string message, object[] args, IFormatProvider formatProvider,
                        string category, string nativeErrorInfo, Exception ex)
        {
            var logEvent = new LogEventInfo
            {
                Level          = ConvertLogLevel(level),
                Message        = message,
                FormatProvider = formatProvider,
                Parameters     = args,
                Exception      = ex,
                LoggerName     = category
            };

            if (nativeErrorInfo != null)
            {
                logEvent.Properties.Add("nativeErrorInfo", nativeErrorInfo);
            }

            _logger.Log(logEvent);
        }
        /// <summary>
        /// Converts the Ignite LogLevel to the NLog log level.
        /// </summary>
        /// <param name="level">The Ignite log level.</param>
        /// <returns>Corresponding NLog log level.</returns>
        public static NLogLogLevel ConvertLogLevel(IgniteLogLevel level)
        {
            switch (level)
            {
            case IgniteLogLevel.Trace:
                return(NLogLogLevel.Trace);

            case IgniteLogLevel.Debug:
                return(NLogLogLevel.Debug);

            case IgniteLogLevel.Info:
                return(NLogLogLevel.Info);

            case IgniteLogLevel.Warn:
                return(NLogLogLevel.Warn);

            case IgniteLogLevel.Error:
                return(NLogLogLevel.Error);

            default:
                throw new ArgumentOutOfRangeException("level", level, "Invalid Ignite LogLevel.");
            }
        }
Beispiel #6
0
 /// <summary>
 /// Determines whether the specified log level is enabled.
 /// </summary>
 /// <param name="level">The level.</param>
 /// <returns>
 /// Value indicating whether the specified log level is enabled
 /// </returns>
 /// <exception cref="System.NotImplementedException"></exception>
 public bool IsEnabled(IgniteLogLevel level)
 {
     return _logger.IsEnabled(ConvertLogLevel(level));
 }
Beispiel #7
0
 /// <summary>
 /// Converts the Ignite LogLevel to the NLog log level.
 /// </summary>
 /// <param name="level">The Ignite log level.</param>
 /// <returns>Corresponding NLog log level.</returns>
 public static NLogLogLevel ConvertLogLevel(IgniteLogLevel level)
 {
     switch (level)
     {
         case IgniteLogLevel.Trace:
             return NLogLogLevel.Trace;
         case IgniteLogLevel.Debug:
             return NLogLogLevel.Debug;
         case IgniteLogLevel.Info:
             return NLogLogLevel.Info;
         case IgniteLogLevel.Warn:
             return NLogLogLevel.Warn;
         case IgniteLogLevel.Error:
             return NLogLogLevel.Error;
         default:
             throw new ArgumentOutOfRangeException("level", level, "Invalid Ignite LogLevel.");
     }
 }
 /// <summary>
 /// Determines whether the specified log level is enabled.
 /// </summary>
 /// <param name="level">The level.</param>
 /// <returns>
 /// Value indicating whether the specified log level is enabled
 /// </returns>
 /// <exception cref="System.NotImplementedException"></exception>
 public bool IsEnabled(IgniteLogLevel level)
 {
     return(_logger.IsEnabled(ConvertLogLevel(level)));
 }