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 Nov 12, 2024
1 parent 79c4015 commit 1a345e4
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 21 deletions.
4 changes: 2 additions & 2 deletions AstarteDeviceSDKCSharp/Device/AstarteDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public async Task Connect()
}
catch (AstarteCryptoException)
{
Trace.WriteLine("Regenerating the cert");
AstarteLogger.Debug("Regenerating the cert", this.GetType().Name);
try
{
await _pairingHandler.RequestNewCertificate();
Expand Down Expand Up @@ -395,7 +395,7 @@ public void OnTransportConnectionError(Exception ex)
{
if (ex is AstarteCryptoException)
{
Trace.WriteLine("Regenerating the cert");
AstarteLogger.Debug("Regenerating the cert", this.GetType().Name);
try
{
Task.Run(() => _pairingHandler.RequestNewCertificate());
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.Warn($"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 @@ -128,7 +128,7 @@ async Task OnConnectedAsync(MqttClientConnectedEventArgs args)
}
else
{
Trace.WriteLine("Transport Connected");
AstarteLogger.Info("Transport Connected", this.GetType().Name);
}

}
Expand Down Expand Up @@ -276,7 +276,7 @@ async Task OnDisconnectAsync(MqttClientDisconnectedEventArgs e)
}
else
{
Trace.WriteLine("The Connection was lost.");
AstarteLogger.Error("The Connection was lost.", this.GetType().Name);
}

}
Expand All @@ -285,8 +285,8 @@ private void OnMessageReceive(MqttApplicationMessageReceivedEventArgs e)
{
object? payload = null;

Trace.WriteLine("Incoming message: "
+ Encoding.UTF8.GetString(e.ApplicationMessage.Payload ?? new byte[0]));
AstarteLogger.Debug("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 @@ -313,7 +313,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 @@ -323,7 +323,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 @@ -335,7 +335,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 @@ -362,7 +362,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 @@ -389,7 +389,7 @@ private void OnMessageReceive(MqttApplicationMessageReceivedEventArgs e)
}
catch (AstartePropertyStorageException ex)
{
Trace.WriteLine(ex.Message);
AstarteLogger.Error(ex.Message, this.GetType().Name);
}
}

Expand Down Expand Up @@ -434,7 +434,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
2 changes: 1 addition & 1 deletion AstarteDeviceSDKCSharp/Utilities/Logger/AstarteLogger.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of Astarte.
*
* Copyright 2023 SECO Mind Srl
* Copyright 2023-2024 SECO Mind Srl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down

0 comments on commit 1a345e4

Please sign in to comment.