Skip to content

Commit

Permalink
Improved logging
Browse files Browse the repository at this point in the history
  • Loading branch information
BarRaider committed Jan 17, 2024
1 parent 3409ab0 commit d16a360
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions barraider-sdtools/Communication/StreamDeckConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ internal Task SendAsync(IMessage message)
}
catch (Exception ex)
{
Logger.Instance.LogMessage(TracingLevel.ERROR, $"SDTools SendAsync Exception: {ex}");
Logger.Instance.LogMessage(TracingLevel.ERROR, $"{this.GetType()} SDTools SendAsync Exception: {ex}");
}
return null;
}
Expand Down Expand Up @@ -208,7 +208,7 @@ internal Task SetImageAsync(Image image, string context, SDKTarget target, int?
}
catch (Exception ex)
{
Logger.Instance.LogMessage(TracingLevel.ERROR, $"SetImageAsync Exception: {ex}");
Logger.Instance.LogMessage(TracingLevel.ERROR, $"{this.GetType()} SetImageAsync Exception: {ex}");
}
return null;
}
Expand Down Expand Up @@ -335,6 +335,10 @@ private async Task RunAsync()
OnConnected?.Invoke(this, new EventArgs());
await ReceiveAsync();
}
catch (Exception ex)
{
Logger.Instance.LogMessage(TracingLevel.FATAL, $"{this.GetType()} ReceiveAsync Exception: {ex}");
}
finally
{
Logger.Instance.LogMessage(TracingLevel.INFO, $"{this.GetType()} RunAsync completed, shutting down");
Expand All @@ -359,6 +363,8 @@ private async Task<WebSocketCloseStatus> ReceiveAsync()
if (result.MessageType == WebSocketMessageType.Close ||
(result.CloseStatus != null && result.CloseStatus.HasValue && result.CloseStatus.Value != WebSocketCloseStatus.Empty))
{
string closeStatus = (result.CloseStatus == null) ? "None" : (result.CloseStatus.HasValue) ? result.CloseStatus.Value.ToString() : "None";
Logger.Instance.LogMessage(TracingLevel.INFO, $"{this.GetType()} Received websocket close message. MessageType: {result.MessageType} CloseStatus: {closeStatus}");
return result.CloseStatus.GetValueOrDefault();
}
else if (result.MessageType == WebSocketMessageType.Text)
Expand Down Expand Up @@ -423,6 +429,7 @@ private async Task<WebSocketCloseStatus> ReceiveAsync()
Logger.Instance.LogMessage(TracingLevel.FATAL, $"{this.GetType()} ReceiveAsync Exception: {ex}");
}

Logger.Instance.LogMessage(TracingLevel.INFO, $"{this.GetType()} ReceiveAsync ended with CancelToken: {cancelTokenSource.IsCancellationRequested} Websocket: {(webSocket == null ? "null" : "valid")}");
return WebSocketCloseStatus.NormalClosure;
}

Expand Down

0 comments on commit d16a360

Please sign in to comment.