feat: log shard ID in ShardConnection logs
This commit is contained in:
parent
fc5825a941
commit
9ab1a873e5
@ -64,7 +64,7 @@ public class Shard
|
|||||||
HeartbeatReceived?.Invoke(latency);
|
HeartbeatReceived?.Invoke(latency);
|
||||||
};
|
};
|
||||||
|
|
||||||
_conn = new ShardConnection(_jsonSerializerOptions, _logger);
|
_conn = new ShardConnection(_jsonSerializerOptions, _logger, info.ShardId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task ShardLoop()
|
private async Task ShardLoop()
|
||||||
|
@ -11,10 +11,13 @@ public class ShardConnection: IAsyncDisposable
|
|||||||
private readonly ShardPacketSerializer _serializer;
|
private readonly ShardPacketSerializer _serializer;
|
||||||
private ClientWebSocket? _client;
|
private ClientWebSocket? _client;
|
||||||
|
|
||||||
public ShardConnection(JsonSerializerOptions jsonSerializerOptions, ILogger logger)
|
private int _id;
|
||||||
|
|
||||||
|
public ShardConnection(JsonSerializerOptions jsonSerializerOptions, ILogger logger, int id)
|
||||||
{
|
{
|
||||||
_logger = logger.ForContext<ShardConnection>();
|
_logger = logger.ForContext<ShardConnection>();
|
||||||
_serializer = new ShardPacketSerializer(jsonSerializerOptions);
|
_serializer = new ShardPacketSerializer(jsonSerializerOptions);
|
||||||
|
_id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public WebSocketState State => _client?.State ?? WebSocketState.Closed;
|
public WebSocketState State => _client?.State ?? WebSocketState.Closed;
|
||||||
@ -52,7 +55,7 @@ public class ShardConnection: IAsyncDisposable
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
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)
|
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"
|
// force close so we can "reset"
|
||||||
await CloseInner(WebSocketCloseStatus.NormalClosure, null);
|
await CloseInner(WebSocketCloseStatus.NormalClosure, null);
|
||||||
}
|
}
|
||||||
@ -98,7 +101,7 @@ public class ShardConnection: IAsyncDisposable
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
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)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
_logger.Error(e, "Error disposing WebSocket connection");
|
_logger.Error(e, "Shard {ShardId}: Error disposing WebSocket connection");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user