fix: modify how exceptions are printed to reduce noise

When an exception occurs during the connect method,
only the exception message will be printed at the Error log level.
The entire stack trace will be printed when at the Verbose level.

fixes #1273
This commit is contained in:
Andrew Welker
2025-07-25 09:13:42 -05:00
parent 43989b9588
commit 31143f56df

View File

@@ -223,10 +223,7 @@ namespace PepperDash.Core
this.LogDebug("Attempting connect");
// Cancel reconnect if running.
if (ReconnectTimer != null)
{
ReconnectTimer.Stop();
}
ReconnectTimer?.Stop();
// Cleanup the old client if it already exists
if (Client != null)
@@ -268,20 +265,26 @@ namespace PepperDash.Core
if (ie is SocketException)
{
this.LogException(ie, "CONNECTION failure: Cannot reach host");
this.LogError("CONNECTION failure: Cannot reach host");
this.LogVerbose(ie, "Exception details: ");
}
if (ie is System.Net.Sockets.SocketException socketException)
{
this.LogException(ie, "Connection failure: Cannot reach {host} on {port}",
this.LogError("Connection failure: Cannot reach {host} on {port}",
Hostname, Port);
this.LogVerbose(socketException, "SocketException details: ");
}
if (ie is SshAuthenticationException)
{
this.LogException(ie, "Authentication failure for username {userName}", Username);
this.LogError("Authentication failure for username {userName}", Username);
this.LogVerbose(ie, "AuthenticationException details: ");
}
else
this.LogException(ie, "Error on connect");
{
this.LogError("Error on connect: {error}", ie.Message);
this.LogVerbose(ie, "Exception details: ");
}
DisconnectLogged = true;
KillClient(SocketStatus.SOCKET_STATUS_CONNECT_FAILED);
@@ -306,7 +309,8 @@ namespace PepperDash.Core
catch (Exception e)
{
var errorLogLevel = DisconnectLogged == true ? Debug.ErrorLogLevel.None : Debug.ErrorLogLevel.Error;
this.LogException(e, "Unhandled exception on connect");
this.LogError("Unhandled exception on connect: {error}", e.Message);
this.LogVerbose(e, "Exception details: ");
DisconnectLogged = true;
KillClient(SocketStatus.SOCKET_STATUS_CONNECT_FAILED);
if (AutoReconnect)
@@ -465,8 +469,7 @@ namespace PepperDash.Core
/// </summary>
void OnConnectionChange()
{
if (ConnectionChange != null)
ConnectionChange(this, new GenericSocketStatusChageEventArgs(this));
ConnectionChange?.Invoke(this, new GenericSocketStatusChageEventArgs(this));
}
#region IBasicCommunication Members
@@ -474,10 +477,7 @@ namespace PepperDash.Core
/// <summary>
/// Sends text to the server
/// </summary>
/// <param name="text"></param>
/// <summary>
/// SendText method
/// </summary>
/// <param name="text">The text to send</param>
public void SendText(string text)
{
try
@@ -514,10 +514,7 @@ namespace PepperDash.Core
/// <summary>
/// Sends Bytes to the server
/// </summary>
/// <param name="bytes"></param>
/// <summary>
/// SendBytes method
/// </summary>
/// <param name="bytes">The bytes to send</param>
public void SendBytes(byte[] bytes)
{
try