feat: log shard ID in ShardConnection logs

This commit is contained in:
spiral 2021-12-23 22:46:38 -05:00
parent fc5825a941
commit 9ab1a873e5
No known key found for this signature in database
GPG Key ID: A6059F0CA0E1BD31
2 changed files with 9 additions and 6 deletions

View File

@ -64,7 +64,7 @@ public class Shard
HeartbeatReceived?.Invoke(latency);
};
_conn = new ShardConnection(_jsonSerializerOptions, _logger);
_conn = new ShardConnection(_jsonSerializerOptions, _logger, info.ShardId);
}
private async Task ShardLoop()

View File

@ -11,10 +11,13 @@ public class ShardConnection: IAsyncDisposable
private readonly ShardPacketSerializer _serializer;
private ClientWebSocket? _client;
public ShardConnection(JsonSerializerOptions jsonSerializerOptions, ILogger logger)
private int _id;
public ShardConnection(JsonSerializerOptions jsonSerializerOptions, ILogger logger, int id)
{
_logger = logger.ForContext<ShardConnection>();
_serializer = new ShardPacketSerializer(jsonSerializerOptions);
_id = id;
}
public WebSocketState State => _client?.State ?? WebSocketState.Closed;
@ -52,7 +55,7 @@ public class ShardConnection: IAsyncDisposable
}
catch (Exception e)
{
_logger.Error(e, "Error sending WebSocket message");
_logger.Error(e, "Shard {ShardId}: Error sending WebSocket message");
}
}
@ -69,7 +72,7 @@ public class ShardConnection: IAsyncDisposable
}
catch (Exception e)
{
_logger.Error(e, "Error reading from WebSocket");
_logger.Error(e, "Shard {ShardId}: Error reading from WebSocket");
// force close so we can "reset"
await CloseInner(WebSocketCloseStatus.NormalClosure, null);
}
@ -98,7 +101,7 @@ public class ShardConnection: IAsyncDisposable
}
catch (Exception e)
{
_logger.Error(e, "Error closing WebSocket connection");
_logger.Error(e, "Shard {ShardId}: Error closing WebSocket connection");
}
}
@ -109,7 +112,7 @@ public class ShardConnection: IAsyncDisposable
}
catch (Exception e)
{
_logger.Error(e, "Error disposing WebSocket connection");
_logger.Error(e, "Shard {ShardId}: Error disposing WebSocket connection");
}
}
}