Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/StackExchange.Redis/ConnectionMultiplexer.Sentinel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ internal void SwitchPrimary(EndPoint? switchBlame, ConnectionMultiplexer connect
var logger = Logger.With(writer);
if (connection.RawConfig.ServiceName is not string serviceName)
{
logger?.LogInformation("Service name not defined.");
logger?.LogInformationServiceNameNotDefined();
return;
}

Expand Down
12 changes: 7 additions & 5 deletions src/StackExchange.Redis/ConnectionMultiplexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1335,14 +1335,16 @@ internal void GetStatus(ILogger? log)
if (log == null) return;

var tmp = GetServerSnapshot();
log?.LogInformation("Endpoint Summary:");
log.LogInformationEndpointSummaryHeader();
foreach (var server in tmp)
{
log?.LogInformation(" " + server.Summary());
log?.LogInformation(" " + server.GetCounters().ToString());
log?.LogInformation(" " + server.GetProfile());
log.LogInformationServerSummary(server.Summary(), server.GetCounters(), server.GetProfile());
}
log?.LogInformation($"Sync timeouts: {Interlocked.Read(ref syncTimeouts)}; async timeouts: {Interlocked.Read(ref asyncTimeouts)}; fire and forget: {Interlocked.Read(ref fireAndForgets)}; last heartbeat: {LastHeartbeatSecondsAgo}s ago");
log.LogInformationTimeoutsSummary(
Interlocked.Read(ref syncTimeouts),
Interlocked.Read(ref asyncTimeouts),
Interlocked.Read(ref fireAndForgets),
LastHeartbeatSecondsAgo);
}

private void ActivateAllServers(ILogger? log)
Expand Down
6 changes: 3 additions & 3 deletions src/StackExchange.Redis/EndPointCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,12 @@ internal async Task ResolveEndPointsAsync(ConnectionMultiplexer multiplexer, ILo
}
else
{
log?.LogInformation($"Using DNS to resolve '{dns.Host}'...");
log?.LogInformationUsingDnsToResolve(dns.Host);
var ips = await Dns.GetHostAddressesAsync(dns.Host).ObserveErrors().ForAwait();
if (ips.Length == 1)
{
ip = ips[0];
log?.LogInformation($"'{dns.Host}' => {ip}");
log?.LogInformationDnsResolutionResult(dns.Host, ip);
cache[dns.Host] = ip;
this[i] = new IPEndPoint(ip, dns.Port);
}
Expand All @@ -223,7 +223,7 @@ internal async Task ResolveEndPointsAsync(ConnectionMultiplexer multiplexer, ILo
catch (Exception ex)
{
multiplexer.OnInternalError(ex);
log?.LogError(ex, ex.Message);
log?.LogErrorDnsResolution(ex, ex.Message);
}
}
}
Expand Down
44 changes: 44 additions & 0 deletions src/StackExchange.Redis/LoggerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -665,4 +665,48 @@ internal static void LogWithThreadPoolStats(this ILogger? log, string message)
EventId = 100,
Message = "{BridgeName}: Connected")]
internal static partial void LogInformationConnected(this ILogger logger, string bridgeName);

// ConnectionMultiplexer GetStatus logging methods
[LoggerMessage(
Level = LogLevel.Information,
EventId = 101,
Message = "Endpoint Summary:")]
internal static partial void LogInformationEndpointSummaryHeader(this ILogger logger);

[LoggerMessage(
Level = LogLevel.Information,
EventId = 102,
Message = "Server summary: {ServerSummary}, counters: {ServerCounters}, profile: {ServerProfile}")]
internal static partial void LogInformationServerSummary(this ILogger logger, string serverSummary, ServerCounters serverCounters, string serverProfile);

[LoggerMessage(
Level = LogLevel.Information,
EventId = 105,
Message = "Sync timeouts: {SyncTimeouts}; async timeouts: {AsyncTimeouts}; fire and forget: {FireAndForgets}; last heartbeat: {LastHeartbeatSecondsAgo}s ago")]
internal static partial void LogInformationTimeoutsSummary(this ILogger logger, long syncTimeouts, long asyncTimeouts, long fireAndForgets, long lastHeartbeatSecondsAgo);

// EndPointCollection logging methods
[LoggerMessage(
Level = LogLevel.Information,
EventId = 106,
Message = "Using DNS to resolve '{DnsHost}'...")]
internal static partial void LogInformationUsingDnsToResolve(this ILogger logger, string dnsHost);

[LoggerMessage(
Level = LogLevel.Information,
EventId = 107,
Message = "'{DnsHost}' => {IpAddress}")]
internal static partial void LogInformationDnsResolutionResult(this ILogger logger, string dnsHost, IPAddress ipAddress);

[LoggerMessage(
Level = LogLevel.Error,
EventId = 108,
Message = "{ErrorMessage}")]
internal static partial void LogErrorDnsResolution(this ILogger logger, Exception exception, string errorMessage);

[LoggerMessage(
Level = LogLevel.Information,
EventId = 109,
Message = "Service name not defined.")]
internal static partial void LogInformationServiceNameNotDefined(this ILogger logger);
}
Loading