public void Setup() { _nullLogger = new MqttNetNullLogger(); _sourceNullLogger = _nullLogger.WithSource("Source"); _eventLogger = new MqttNetEventLogger(); _eventLogger.LogMessagePublished += OnLogMessagePublished; _sourceEventLogger = _eventLogger.WithSource("Source"); _eventLoggerNoListener = new MqttNetEventLogger(); _sourceEventLoggerNoListener = _eventLoggerNoListener.WithSource("Source"); }
public void Use_Custom_Log_Id() { var logger = new MqttNetEventLogger("logId"); var childLogger = logger.WithSource("Source1"); logger.LogMessagePublished += (s, e) => { Assert.AreEqual("logId", e.LogMessage.LogId); Assert.AreEqual("Source1", e.LogMessage.Source); }; childLogger.Verbose("Verbose"); childLogger.Info("Info"); childLogger.Warning((Exception)null, "Warning"); childLogger.Error(null, "Error"); }
public void Root_Log_Messages() { var logger = new MqttNetEventLogger(); var childLogger = logger.WithSource("Source1"); var logMessagesCount = 0; logger.LogMessagePublished += (s, e) => { logMessagesCount++; }; childLogger.Verbose("Verbose"); childLogger.Info("Info"); childLogger.Warning((Exception)null, "Warning"); childLogger.Error(null, "Error"); Assert.AreEqual(4, logMessagesCount); }
public void Log_With_Source() { MqttNetLogMessage logMessage = null; var logger = new MqttNetEventLogger(); logger.LogMessagePublished += (s, e) => { logMessage = e.LogMessage; }; var sourceLogger = logger.WithSource("The_Source"); sourceLogger.Info("MESSAGE", null, null); Assert.AreEqual("The_Source", logMessage.Source); }