Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions src/StackExchange.Redis/LoggerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -488,4 +488,101 @@ internal static void LogWithThreadPoolStats(this ILogger? log, string message)
EventId = 70,
Message = "{Server}: Flushing outbound buffer")]
internal static partial void LogInformationFlushingOutboundBuffer(this ILogger logger, ServerEndPointLogValue server);

// ResultProcessor logging methods
[LoggerMessage(
Level = LogLevel.Information,
EventId = 71,
Message = "Response from {BridgeName} / {CommandAndKey}: {Result}")]
internal static partial void LogInformationResponse(this ILogger logger, string? bridgeName, string commandAndKey, RawResult result);

[LoggerMessage(
Level = LogLevel.Information,
EventId = 72,
Message = "{Server}: Auto-configured role: replica")]
internal static partial void LogInformationAutoConfiguredRoleReplica(this ILogger logger, ServerEndPointLogValue server);

[LoggerMessage(
Level = LogLevel.Information,
EventId = 73,
Message = "{Server}: Auto-configured (CLIENT) connection-id: {ConnectionId}")]
internal static partial void LogInformationAutoConfiguredClientConnectionId(this ILogger logger, ServerEndPointLogValue server, long connectionId);

[LoggerMessage(
Level = LogLevel.Information,
EventId = 74,
Message = "{Server}: Auto-configured (INFO) role: {Role}")]
internal static partial void LogInformationAutoConfiguredInfoRole(this ILogger logger, ServerEndPointLogValue server, string role);

[LoggerMessage(
Level = LogLevel.Information,
EventId = 75,
Message = "{Server}: Auto-configured (INFO) version: {Version}")]
internal static partial void LogInformationAutoConfiguredInfoVersion(this ILogger logger, ServerEndPointLogValue server, Version version);

[LoggerMessage(
Level = LogLevel.Information,
EventId = 76,
Message = "{Server}: Auto-configured (INFO) server-type: {ServerType}")]
internal static partial void LogInformationAutoConfiguredInfoServerType(this ILogger logger, ServerEndPointLogValue server, ServerType serverType);

[LoggerMessage(
Level = LogLevel.Information,
EventId = 77,
Message = "{Server}: Auto-configured (SENTINEL) server-type: sentinel")]
internal static partial void LogInformationAutoConfiguredSentinelServerType(this ILogger logger, ServerEndPointLogValue server);

[LoggerMessage(
Level = LogLevel.Information,
EventId = 78,
Message = "{Server}: Auto-configured (CONFIG) timeout: {TimeoutSeconds}s")]
internal static partial void LogInformationAutoConfiguredConfigTimeout(this ILogger logger, ServerEndPointLogValue server, int timeoutSeconds);

[LoggerMessage(
Level = LogLevel.Information,
EventId = 79,
Message = "{Server}: Auto-configured (CONFIG) databases: {DatabaseCount}")]
internal static partial void LogInformationAutoConfiguredConfigDatabases(this ILogger logger, ServerEndPointLogValue server, int databaseCount);

[LoggerMessage(
Level = LogLevel.Information,
EventId = 80,
Message = "{Server}: Auto-configured (CONFIG) read-only replica: true")]
internal static partial void LogInformationAutoConfiguredConfigReadOnlyReplicaTrue(this ILogger logger, ServerEndPointLogValue server);

[LoggerMessage(
Level = LogLevel.Information,
EventId = 81,
Message = "{Server}: Auto-configured (CONFIG) read-only replica: false")]
internal static partial void LogInformationAutoConfiguredConfigReadOnlyReplicaFalse(this ILogger logger, ServerEndPointLogValue server);

[LoggerMessage(
Level = LogLevel.Information,
EventId = 82,
Message = "{Server}: Auto-configured (HELLO) server-version: {Version}")]
internal static partial void LogInformationAutoConfiguredHelloServerVersion(this ILogger logger, ServerEndPointLogValue server, Version version);

[LoggerMessage(
Level = LogLevel.Information,
EventId = 83,
Message = "{Server}: Auto-configured (HELLO) protocol: {Protocol}")]
internal static partial void LogInformationAutoConfiguredHelloProtocol(this ILogger logger, ServerEndPointLogValue server, RedisProtocol protocol);

[LoggerMessage(
Level = LogLevel.Information,
EventId = 84,
Message = "{Server}: Auto-configured (HELLO) connection-id: {ConnectionId}")]
internal static partial void LogInformationAutoConfiguredHelloConnectionId(this ILogger logger, ServerEndPointLogValue server, long connectionId);

[LoggerMessage(
Level = LogLevel.Information,
EventId = 85,
Message = "{Server}: Auto-configured (HELLO) server-type: {ServerType}")]
internal static partial void LogInformationAutoConfiguredHelloServerType(this ILogger logger, ServerEndPointLogValue server, ServerType serverType);

[LoggerMessage(
Level = LogLevel.Information,
EventId = 86,
Message = "{Server}: Auto-configured (HELLO) role: {Role}")]
internal static partial void LogInformationAutoConfiguredHelloRole(this ILogger logger, ServerEndPointLogValue server, string role);
}
34 changes: 17 additions & 17 deletions src/StackExchange.Redis/ResultProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public virtual bool SetResult(PhysicalConnection connection, Message message, in
{
try
{
logging.Log?.LogInformation($"Response from {bridge?.Name} / {message.CommandAndKey}: {result}");
logging.Log?.LogInformationResponse(bridge?.Name, message.CommandAndKey, result);
}
catch { }
}
Expand Down Expand Up @@ -816,7 +816,7 @@ public override bool SetResult(PhysicalConnection connection, Message message, i
if (bridge != null)
{
var server = bridge.ServerEndPoint;
Log?.LogInformation($"{Format.ToString(server)}: Auto-configured role: replica");
Log?.LogInformationAutoConfiguredRoleReplica(new(server));
server.IsReplica = true;
}
}
Expand All @@ -837,7 +837,7 @@ protected override bool SetResultCore(PhysicalConnection connection, Message mes
if (result.TryGetInt64(out long clientId))
{
connection.ConnectionId = clientId;
Log?.LogInformation($"{Format.ToString(server)}: Auto-configured (CLIENT) connection-id: {clientId}");
Log?.LogInformationAutoConfiguredClientConnectionId(new(server), clientId);

SetResult(message, true);
return true;
Expand Down Expand Up @@ -871,7 +871,7 @@ protected override bool SetResultCore(PhysicalConnection connection, Message mes
if (TryParseRole(val, out bool isReplica))
{
server.IsReplica = isReplica;
Log?.LogInformation($"{Format.ToString(server)}: Auto-configured (INFO) role: {(isReplica ? "replica" : "primary")}");
Log?.LogInformationAutoConfiguredInfoRole(new(server), isReplica ? "replica" : "primary");
}
}
else if ((val = Extract(line, "master_host:")) != null)
Expand All @@ -887,15 +887,15 @@ protected override bool SetResultCore(PhysicalConnection connection, Message mes
if (Format.TryParseVersion(val, out Version? version))
{
server.Version = version;
Log?.LogInformation($"{Format.ToString(server)}: Auto-configured (INFO) version: " + version);
Log?.LogInformationAutoConfiguredInfoVersion(new(server), version);
}
}
else if ((val = Extract(line, "redis_mode:")) != null)
{
if (TryParseServerType(val, out var serverType))
{
server.ServerType = serverType;
Log?.LogInformation($"{Format.ToString(server)}: Auto-configured (INFO) server-type: {serverType}");
Log?.LogInformationAutoConfiguredInfoServerType(new(server), serverType);
}
}
else if ((val = Extract(line, "run_id:")) != null)
Expand All @@ -913,7 +913,7 @@ protected override bool SetResultCore(PhysicalConnection connection, Message mes
else if (message?.Command == RedisCommand.SENTINEL)
{
server.ServerType = ServerType.Sentinel;
Log?.LogInformation($"{Format.ToString(server)}: Auto-configured (SENTINEL) server-type: sentinel");
Log?.LogInformationAutoConfiguredSentinelServerType(new(server));
}
SetResult(message, true);
return true;
Expand Down Expand Up @@ -941,14 +941,14 @@ protected override bool SetResultCore(PhysicalConnection connection, Message mes
{
targetSeconds = (timeoutSeconds * 3) / 4;
}
Log?.LogInformation($"{Format.ToString(server)}: Auto-configured (CONFIG) timeout: " + targetSeconds + "s");
Log?.LogInformationAutoConfiguredConfigTimeout(new(server), targetSeconds);
server.WriteEverySeconds = targetSeconds;
}
}
else if (key.IsEqual(CommonReplies.databases) && val.TryGetInt64(out i64))
{
int dbCount = checked((int)i64);
Log?.LogInformation($"{Format.ToString(server)}: Auto-configured (CONFIG) databases: " + dbCount);
Log?.LogInformationAutoConfiguredConfigDatabases(new(server), dbCount);
server.Databases = dbCount;
if (dbCount > 1)
{
Expand All @@ -960,12 +960,12 @@ protected override bool SetResultCore(PhysicalConnection connection, Message mes
if (val.IsEqual(CommonReplies.yes))
{
server.ReplicaReadOnly = true;
Log?.LogInformation($"{Format.ToString(server)}: Auto-configured (CONFIG) read-only replica: true");
Log?.LogInformationAutoConfiguredConfigReadOnlyReplicaTrue(new(server));
Copy link
Collaborator

@mgravell mgravell Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we merge I have merged these two and make the true/false a bool parameter? I'm fine with the case changing if we use default logging

}
else if (val.IsEqual(CommonReplies.no))
{
server.ReplicaReadOnly = false;
Log?.LogInformation($"{Format.ToString(server)}: Auto-configured (CONFIG) read-only replica: false");
Log?.LogInformationAutoConfiguredConfigReadOnlyReplicaFalse(new(server));
}
}
}
Expand All @@ -982,34 +982,34 @@ protected override bool SetResultCore(PhysicalConnection connection, Message mes
if (key.IsEqual(CommonReplies.version) && Format.TryParseVersion(val.GetString(), out var version))
{
server.Version = version;
Log?.LogInformation($"{Format.ToString(server)}: Auto-configured (HELLO) server-version: {version}");
Log?.LogInformationAutoConfiguredHelloServerVersion(new(server), version);
}
else if (key.IsEqual(CommonReplies.proto) && val.TryGetInt64(out var i64))
{
connection.SetProtocol(i64 >= 3 ? RedisProtocol.Resp3 : RedisProtocol.Resp2);
Log?.LogInformation($"{Format.ToString(server)}: Auto-configured (HELLO) protocol: {connection.Protocol}");
Log?.LogInformationAutoConfiguredHelloProtocol(new(server), connection.Protocol ?? RedisProtocol.Resp2);
}
else if (key.IsEqual(CommonReplies.id) && val.TryGetInt64(out i64))
{
connection.ConnectionId = i64;
Log?.LogInformation($"{Format.ToString(server)}: Auto-configured (HELLO) connection-id: {i64}");
Log?.LogInformationAutoConfiguredHelloConnectionId(new(server), i64);
}
else if (key.IsEqual(CommonReplies.mode) && TryParseServerType(val.GetString(), out var serverType))
{
server.ServerType = serverType;
Log?.LogInformation($"{Format.ToString(server)}: Auto-configured (HELLO) server-type: {serverType}");
Log?.LogInformationAutoConfiguredHelloServerType(new(server), serverType);
}
else if (key.IsEqual(CommonReplies.role) && TryParseRole(val.GetString(), out bool isReplica))
{
server.IsReplica = isReplica;
Log?.LogInformation($"{Format.ToString(server)}: Auto-configured (HELLO) role: {(isReplica ? "replica" : "primary")}");
Log?.LogInformationAutoConfiguredHelloRole(new(server), isReplica ? "replica" : "primary");
}
}
}
else if (message?.Command == RedisCommand.SENTINEL)
{
server.ServerType = ServerType.Sentinel;
Log?.LogInformation($"{Format.ToString(server)}: Auto-configured (SENTINEL) server-type: sentinel");
Log?.LogInformationAutoConfiguredSentinelServerType(new(server));
}
SetResult(message, true);
return true;
Expand Down
Loading