diff --git a/AstarteDeviceSDKCSharp/Device/AstarteDevice.cs b/AstarteDeviceSDKCSharp/Device/AstarteDevice.cs index 4d4ae15..81ba3e9 100644 --- a/AstarteDeviceSDKCSharp/Device/AstarteDevice.cs +++ b/AstarteDeviceSDKCSharp/Device/AstarteDevice.cs @@ -243,7 +243,7 @@ public async Task Connect() } catch (AstarteCryptoException) { - Trace.WriteLine("Regenerating the cert"); + AstarteLogger.Info("Regenerating the cert", this.GetType().Name); try { await _pairingHandler.RequestNewCertificate(); @@ -425,7 +425,7 @@ public void OnTransportConnectionInitializationError(Exception ex) } catch (AstarteTransportException e) { - Trace.WriteLine(e.Message); + AstarteLogger.Warn(e.Message, this.GetType().Name); } EventualyReconnect(); }).Start(); @@ -439,7 +439,7 @@ public void OnTransportConnectionError(Exception ex) { if (ex is AstarteCryptoException) { - Trace.WriteLine("Regenerating the cert"); + AstarteLogger.Info("Regenerating the cert", this.GetType().Name); try { Task.Run(() => _pairingHandler.RequestNewCertificate()); @@ -452,7 +452,7 @@ public void OnTransportConnectionError(Exception ex) _astarteMessagelistener? .OnFailure(new AstarteMessageException(e.Message, e)); - Trace.WriteLine(e); + AstarteLogger.Warn(e.Message, this.GetType().Name); } return; } diff --git a/AstarteDeviceSDKCSharp/Protocol/AstarteDeviceAggregateDatastreamInterface.cs b/AstarteDeviceSDKCSharp/Protocol/AstarteDeviceAggregateDatastreamInterface.cs index c8345d6..3d7ad91 100644 --- a/AstarteDeviceSDKCSharp/Protocol/AstarteDeviceAggregateDatastreamInterface.cs +++ b/AstarteDeviceSDKCSharp/Protocol/AstarteDeviceAggregateDatastreamInterface.cs @@ -84,9 +84,9 @@ public void ValidatePayload(string path, Dictionary payload, Dat if (astarteInterfaceMapping.Path is null) { - Trace.WriteLine("Astarte mapping path " + + AstarteLogger.Warn("Astarte mapping path " + "{" + astarteInterfaceMapping.Path + " } " - + " is null."); + + " is null.", this.GetType().Name); continue; } if (!payload.ContainsKey( diff --git a/AstarteDeviceSDKCSharp/Protocol/AstarteDevicePropertyInterface.cs b/AstarteDeviceSDKCSharp/Protocol/AstarteDevicePropertyInterface.cs index 2c25a88..08ed871 100644 --- a/AstarteDeviceSDKCSharp/Protocol/AstarteDevicePropertyInterface.cs +++ b/AstarteDeviceSDKCSharp/Protocol/AstarteDevicePropertyInterface.cs @@ -55,7 +55,7 @@ public void SetProperty(string path, object payload) } catch (AstartePropertyStorageException e) { - Trace.WriteLine(e.Message); + AstarteLogger.Error(e.Message, this.GetType().Name); } if (!(storedValue?.PayloadEquality(payload) ?? false)) diff --git a/AstarteDeviceSDKCSharp/Protocol/AstarteServerAggregateDatastreamInterface.cs b/AstarteDeviceSDKCSharp/Protocol/AstarteServerAggregateDatastreamInterface.cs index 4fd9bb6..bc4c238 100644 --- a/AstarteDeviceSDKCSharp/Protocol/AstarteServerAggregateDatastreamInterface.cs +++ b/AstarteDeviceSDKCSharp/Protocol/AstarteServerAggregateDatastreamInterface.cs @@ -51,7 +51,7 @@ public void RemoveListener(IAstarteAggregateDatastreamEventListener listener) { if (serverValue is null) { - Trace.WriteLine("Unable to build AstarteServerValue, serverValue was empty"); + AstarteLogger.Error("Unable to build AstarteServerValue, serverValue was empty", this.GetType().Name); return null; } @@ -63,7 +63,7 @@ public void RemoveListener(IAstarteAggregateDatastreamEventListener listener) if (astartePayload is null) { - Trace.WriteLine("Unable to build AstarteServerValue, astartePayload was empty"); + AstarteLogger.Error("Unable to build AstarteServerValue, astartePayload was empty", this.GetType().Name); return null; } diff --git a/AstarteDeviceSDKCSharp/Protocol/AstarteServerDatastreamInterface.cs b/AstarteDeviceSDKCSharp/Protocol/AstarteServerDatastreamInterface.cs index d890daa..199ec95 100644 --- a/AstarteDeviceSDKCSharp/Protocol/AstarteServerDatastreamInterface.cs +++ b/AstarteDeviceSDKCSharp/Protocol/AstarteServerDatastreamInterface.cs @@ -58,7 +58,7 @@ public void RemoveListener(IAstarteDatastreamEventListener listener) AstarteInterfaceMapping? targetMapping = null; if (serverValue is null) { - Trace.WriteLine($"Unable to build AstarteServerValue, astartePayload was empty"); + AstarteLogger.Error("Unable to build AstarteServerValue, astartePayload was empty", this.GetType().Name); return null; } @@ -87,8 +87,9 @@ public void RemoveListener(IAstarteDatastreamEventListener listener) } else { - Trace.WriteLine($"Got an unexpected path {interfacePath}" - + "for interface {GetInterfaceName()}"); + AstarteLogger.Info($"Got an unexpected path {interfacePath}" + + "for interface {GetInterfaceName()}", this.GetType().Name); + } return astarteServerValue; } diff --git a/AstarteDeviceSDKCSharp/Transport/MQTT/AstarteMqttTransport.cs b/AstarteDeviceSDKCSharp/Transport/MQTT/AstarteMqttTransport.cs index 81cbaa4..1e34fab 100644 --- a/AstarteDeviceSDKCSharp/Transport/MQTT/AstarteMqttTransport.cs +++ b/AstarteDeviceSDKCSharp/Transport/MQTT/AstarteMqttTransport.cs @@ -91,7 +91,7 @@ private async Task CompleteAstarteConnection(bool IsSessionPresent) } else { - Trace.WriteLine("Transport Connected"); + AstarteLogger.Info("Transport Connected", this.GetType().Name); } _client.UseApplicationMessageReceivedHandler(OnMessageReceive); @@ -208,7 +208,7 @@ private Task OnDisconnectAsync(MqttClientDisconnectedEventArgs e) } else { - Trace.WriteLine("The Connection was lost."); + AstarteLogger.Error("The Connection was lost.", this.GetType().Name); } return Task.CompletedTask; @@ -218,8 +218,8 @@ private void OnMessageReceive(MqttApplicationMessageReceivedEventArgs e) { object? payload = null; - Trace.WriteLine("Incoming message: " - + Encoding.UTF8.GetString(e.ApplicationMessage.Payload ?? new byte[0])); + AstarteLogger.Error("Incoming message: " + + Encoding.UTF8.GetString(e.ApplicationMessage.Payload ?? new byte[0]), this.GetType().Name); if (!e.ApplicationMessage.Topic.Contains(_connectionInfo.GetClientId()) || _messageListener == null) @@ -246,7 +246,7 @@ private void OnMessageReceive(MqttApplicationMessageReceivedEventArgs e) } else { - Trace.WriteLine("Unhandled control message!" + path); + AstarteLogger.Error("Unhandled control message!" + path, this.GetType().Name); } return; } @@ -256,7 +256,7 @@ private void OnMessageReceive(MqttApplicationMessageReceivedEventArgs e) if (!astarteDevice.HasInterface(astarteInterface)) { - Trace.WriteLine("Got an unexpected interface!" + astarteInterface); + AstarteLogger.Warn("Got an unexpected interface!" + astarteInterface, this.GetType().Name); return; } @@ -268,7 +268,7 @@ private void OnMessageReceive(MqttApplicationMessageReceivedEventArgs e) decodedMessage = AstartePayload.Deserialize(e.ApplicationMessage.Payload); if (decodedMessage is null) { - Trace.WriteLine("Unable to get payload, decodedMessage was null"); + AstarteLogger.Warn("Unable to get payload, decodedMessage was null ", this.GetType().Name); return; } payload = decodedMessage.GetPayload(); @@ -295,7 +295,7 @@ private void OnMessageReceive(MqttApplicationMessageReceivedEventArgs e) if (astarteServerValue == null) { - Trace.WriteLine("Unable to get value, astarteServerValue was null"); + AstarteLogger.Error("Unable to get value, astarteServerValue was null", this.GetType().Name); return; } @@ -322,7 +322,7 @@ private void OnMessageReceive(MqttApplicationMessageReceivedEventArgs e) } catch (AstartePropertyStorageException ex) { - Trace.WriteLine(ex.Message); + AstarteLogger.Error(ex.Message, this.GetType().Name); } } @@ -367,7 +367,7 @@ private void HandlePurgeProperties(byte[] payload, AstarteDevice? astarteDevice) } catch (IOException e) { - Trace.WriteLine(e.Message); + AstarteLogger.Error(e.Message, this.GetType().Name); } string purgePropertiesPayload = result.ToString();