Beispiel #1
0
        public void Publish(MqttNetLogLevel logLevel, string source, string message, object[] parameters, Exception exception)
        {
            var newLogLevel = LogLevel.Debug;

            if (logLevel == MqttNetLogLevel.Warning)
            {
                newLogLevel = LogLevel.Warning;
            }
            else if (logLevel == MqttNetLogLevel.Error)
            {
                newLogLevel = LogLevel.Error;
            }
            else if (logLevel == MqttNetLogLevel.Info)
            {
                newLogLevel = LogLevel.Information;
            }
            else if (logLevel == MqttNetLogLevel.Verbose)
            {
                newLogLevel = LogLevel.Trace;
            }

            _logger.Log(newLogLevel, source, exception, message, parameters);

            LogMessagePublished?.Invoke(this, new MqttNetLogMessagePublishedEventArgs(null));
        }
Beispiel #2
0
        private void Publish <TSource>(MqttNetLogLevel logLevel, Exception exception, string message, object[] parameters)
        {
            var hasLocalListeners  = LogMessagePublished != null;
            var hasGlobalListeners = MqttNetGlobalLog.HasListeners;

            if (!hasLocalListeners && !hasGlobalListeners)
            {
                return;
            }

            if (parameters.Length > 0)
            {
                message = string.Format(message, parameters);
            }

            var traceMessage = new MqttNetLogMessage(_logId, DateTime.Now, Environment.CurrentManagedThreadId, typeof(TSource).Name, logLevel, message, exception);

            if (hasGlobalListeners)
            {
                MqttNetGlobalLog.Publish(traceMessage);
            }

            if (hasLocalListeners)
            {
                LogMessagePublished?.Invoke(this, new MqttNetLogMessagePublishedEventArgs(traceMessage));
            }
        }
Beispiel #3
0
        public void Publish(MqttNetLogLevel logLevel, string source, string message, object[] parameters, Exception exception)
        {
            var hasLocalListeners  = LogMessagePublished != null;
            var hasGlobalListeners = MqttNetGlobalLogger.HasListeners;

            if (!hasLocalListeners && !hasGlobalListeners)
            {
                return;
            }

            if (parameters?.Length > 0)
            {
                try
                {
                    message = string.Format(message, parameters);
                }
                catch
                {
                    message = "MESSAGE FORMAT INVALID: " + message;
                }
            }

            var traceMessage = new MqttNetLogMessage(_logId, DateTime.UtcNow, Environment.CurrentManagedThreadId, source, logLevel, message, exception);

            if (hasGlobalListeners)
            {
                MqttNetGlobalLogger.Publish(traceMessage);
            }

            if (hasLocalListeners)
            {
                LogMessagePublished?.Invoke(this, new MqttNetLogMessagePublishedEventArgs(traceMessage));
            }
        }
Beispiel #4
0
 public void Publish(MqttNetLogLevel logLevel, string message, object[] parameters, Exception exception)
 {
     LogMessagePublished?.Invoke(this, new MqttNetLogMessagePublishedEventArgs(new MqttNetLogMessage
     {
         Level   = logLevel,
         Message = message
     }));
 }
Beispiel #5
0
        public static void Publish(MqttNetLogMessage logMessage)
        {
            if (logMessage == null)
            {
                throw new ArgumentNullException(nameof(logMessage));
            }

            LogMessagePublished?.Invoke(null, new MqttNetLogMessagePublishedEventArgs(logMessage));
        }
Beispiel #6
0
 public void Publish(MqttNetLogLevel logLevel, string source, string message, object[] parameters, Exception exception)
 {
     LogMessagePublished?.Invoke(this, new MqttNetLogMessagePublishedEventArgs(new MqttNetLogMessage
     {
         Level     = logLevel,
         Message   = string.Format(message, parameters),
         Exception = exception
     }));
 }
Beispiel #7
0
        public void Publish(MqttNetLogLevel level, string source, string message, object[] parameters, Exception exception)
        {
            var hasLocalListeners  = LogMessagePublished != null;
            var hasGlobalListeners = MqttNetGlobalLogger.HasListeners;

            if (!hasLocalListeners && !hasGlobalListeners)
            {
                return;
            }

            try
            {
                message = string.Format(message ?? string.Empty, parameters);
            }
            catch (FormatException)
            {
                message = "MESSAGE FORMAT INVALID: " + message;
            }


            var logMessage = new MqttNetLogMessage
            {
                LogId     = _logId,
                Timestamp = DateTime.UtcNow,
                Source    = source,
                ThreadId  =
#if NET40
                    Thread.CurrentThread.ManagedThreadId,
#else
                    Environment.CurrentManagedThreadId,
#endif
                Level     = level,
                Message   = message,
                Exception = exception
            };

            if (hasGlobalListeners)
            {
                MqttNetGlobalLogger.Publish(logMessage);
            }

            if (hasLocalListeners)
            {
                LogMessagePublished?.Invoke(this, new MqttNetLogMessagePublishedEventArgs(logMessage));
            }
        }
    }
Beispiel #8
0
        public void Publish(MqttNetLogLevel level, string message, object[] parameters, Exception exception)
        {
            var hasLocalListeners  = LogMessagePublished != null;
            var hasGlobalListeners = MqttNetGlobalLogger.HasListeners;

            if (!hasLocalListeners && !hasGlobalListeners && _parentLogger == null)
            {
                return;
            }

            if (parameters?.Length > 0)
            {
                try
                {
                    message = string.Format(message, parameters);
                }
                catch
                {
                    message = "MESSAGE FORMAT INVALID: " + message;
                }
            }

            var logMessage = new MqttNetLogMessage
            {
                LogId     = _logId,
                Timestamp = DateTime.UtcNow,
                Source    = _source,
                ThreadId  = Environment.CurrentManagedThreadId,
                Level     = level,
                Message   = message,
                Exception = exception
            };

            if (hasGlobalListeners)
            {
                MqttNetGlobalLogger.Publish(logMessage);
            }

            if (hasLocalListeners)
            {
                LogMessagePublished?.Invoke(this, new MqttNetLogMessagePublishedEventArgs(logMessage));
            }

            _parentLogger?.Publish(logMessage);
        }
Beispiel #9
0
 public void NotifyLogMessagePublished(MqttNetLogMessage logMessage)
 {
     LogMessagePublished?.Invoke(this, new MqttNetLogMessagePublishedEventArgs(logMessage));
 }
 public static void Publish(MqttNetLogMessage logMessage)
 {
     LogMessagePublished?.Invoke(null, new MqttNetLogMessagePublishedEventArgs(logMessage));
 }
Beispiel #11
0
        void Publish(MqttNetLogMessage logMessage)
        {
            LogMessagePublished?.Invoke(this, new MqttNetLogMessagePublishedEventArgs(logMessage));

            _parentLogger?.Publish(logMessage);
        }