Skip to content

Commit

Permalink
Replace Trace.WritteLine with AstarteLogger.LogLevel
Browse files Browse the repository at this point in the history
Signed-off-by: Osman Hadzic <osman.hadzic@secomind.com>
  • Loading branch information
osmanhadzic committed Dec 4, 2023
1 parent 6282302 commit cc0914d
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 22 deletions.
8 changes: 4 additions & 4 deletions AstarteDeviceSDKCSharp/Device/AstarteDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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());
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ public void ValidatePayload(string path, Dictionary<string, object> 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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down
20 changes: 10 additions & 10 deletions AstarteDeviceSDKCSharp/Transport/MQTT/AstarteMqttTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -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;
}
Expand All @@ -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;
}

Expand All @@ -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();
Expand All @@ -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;
}

Expand All @@ -322,7 +322,7 @@ private void OnMessageReceive(MqttApplicationMessageReceivedEventArgs e)
}
catch (AstartePropertyStorageException ex)
{
Trace.WriteLine(ex.Message);
AstarteLogger.Error(ex.Message, this.GetType().Name);
}
}

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit cc0914d

Please sign in to comment.