internal void Publish(Alert alert) { try { if (this.mqttClient != null) { if (this.IsConnected) { string Alert = JsonConvert.SerializeObject(alert); mqttClient.Publish("/redalert/", Encoding.UTF8.GetBytes(Alert), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false); } } } catch (Exception ex) { if (this.OnError != null) { ExceptionEventArgs args = new ExceptionEventArgs(); args.exeption = ex; args.MethodName = "MqttPublisher.Publish"; this.OnError(this, args); } } }
void _mqttPublisher_OnError(object sender, ExceptionEventArgs e) { Logger(e.exeption); }