Skip to content

Commit 6b09407

Browse files
committed
Clean up logging in configuration-based service endpoint provider
1 parent 2df7ccf commit 6b09407

File tree

2 files changed

+13
-32
lines changed

2 files changed

+13
-32
lines changed
Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using System.Globalization;
54
using System.Text;
65
using Microsoft.Extensions.Logging;
76

@@ -14,60 +13,38 @@ private sealed partial class Log
1413
[LoggerMessage(1, LogLevel.Debug, "Skipping endpoint resolution for service '{ServiceName}': '{Reason}'.", EventName = "SkippedResolution")]
1514
public static partial void SkippedResolution(ILogger logger, string serviceName, string reason);
1615

17-
[LoggerMessage(2, LogLevel.Debug, "Matching endpoints using endpoint names for service '{ServiceName}' since endpoint names are specified in configuration.", EventName = "MatchingEndPointNames")]
18-
public static partial void MatchingEndPointNames(ILogger logger, string serviceName);
19-
20-
[LoggerMessage(3, LogLevel.Debug, "Ignoring endpoints using endpoint names for service '{ServiceName}' since no endpoint names are specified in configuration.", EventName = "IgnoringEndPointNames")]
21-
public static partial void IgnoringEndPointNames(ILogger logger, string serviceName);
22-
23-
public static void EndPointNameMatchSelection(ILogger logger, string serviceName, bool matchEndPointNames)
24-
{
25-
if (!logger.IsEnabled(LogLevel.Debug))
26-
{
27-
return;
28-
}
29-
30-
if (matchEndPointNames)
31-
{
32-
MatchingEndPointNames(logger, serviceName);
33-
}
34-
else
35-
{
36-
IgnoringEndPointNames(logger, serviceName);
37-
}
38-
}
39-
40-
[LoggerMessage(4, LogLevel.Debug, "Using configuration from path '{Path}' to resolve endpoint '{EndpointName}' for service '{ServiceName}'.", EventName = "UsingConfigurationPath")]
16+
[LoggerMessage(2, LogLevel.Debug, "Using configuration from path '{Path}' to resolve endpoint '{EndpointName}' for service '{ServiceName}'.", EventName = "UsingConfigurationPath")]
4117
public static partial void UsingConfigurationPath(ILogger logger, string path, string endpointName, string serviceName);
4218

43-
[LoggerMessage(5, LogLevel.Debug, "No valid endpoint configuration was found for service '{ServiceName}' from path '{Path}'.", EventName = "ServiceConfigurationNotFound")]
19+
[LoggerMessage(3, LogLevel.Debug, "No valid endpoint configuration was found for service '{ServiceName}' from path '{Path}'.", EventName = "ServiceConfigurationNotFound")]
4420
internal static partial void ServiceConfigurationNotFound(ILogger logger, string serviceName, string path);
4521

46-
[LoggerMessage(6, LogLevel.Debug, "Endpoints configured for service '{ServiceName}' from path '{Path}': {ConfiguredEndPoints}.", EventName = "ConfiguredEndPoints")]
22+
[LoggerMessage(4, LogLevel.Debug, "Endpoints configured for service '{ServiceName}' from path '{Path}': {ConfiguredEndPoints}.", EventName = "ConfiguredEndPoints")]
4723
internal static partial void ConfiguredEndPoints(ILogger logger, string serviceName, string path, string configuredEndPoints);
48-
public static void ConfiguredEndPoints(ILogger logger, string serviceName, string path, List<ServiceEndPointQuery> parsedValues)
24+
25+
internal static void ConfiguredEndPoints(ILogger logger, string serviceName, string path, IList<ServiceEndPoint> endpoints, int added)
4926
{
5027
if (!logger.IsEnabled(LogLevel.Debug))
5128
{
5229
return;
5330
}
5431

5532
StringBuilder endpointValues = new();
56-
for (var i = 0; i < parsedValues.Count; i++)
33+
for (var i = endpoints.Count - added; i < endpoints.Count; i++)
5734
{
5835
if (endpointValues.Length > 0)
5936
{
6037
endpointValues.Append(", ");
6138
}
6239

63-
endpointValues.Append(CultureInfo.InvariantCulture, $"({parsedValues[i]})");
40+
endpointValues.Append(endpoints[i].ToString());
6441
}
6542

6643
var configuredEndPoints = endpointValues.ToString();
6744
ConfiguredEndPoints(logger, serviceName, path, configuredEndPoints);
6845
}
6946

70-
[LoggerMessage(7, LogLevel.Debug, "No valid endpoint configuration was found for endpoint '{EndpointName}' on service '{ServiceName}' from path '{Path}'.", EventName = "EndpointConfigurationNotFound")]
47+
[LoggerMessage(5, LogLevel.Debug, "No valid endpoint configuration was found for endpoint '{EndpointName}' on service '{ServiceName}' from path '{Path}'.", EventName = "EndpointConfigurationNotFound")]
7148
internal static partial void EndpointConfigurationNotFound(ILogger logger, string endpointName, string serviceName, string path);
7249
}
7350
}

src/Microsoft.Extensions.ServiceDiscovery/Configuration/ConfigurationServiceEndPointResolver.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public ValueTask ResolveAsync(ServiceEndPointCollectionSource endPoints, Cancell
106106
var configPath = $"{_options.Value.SectionName}:{_serviceName}:{endpointName}";
107107
if (!namedSection.Exists())
108108
{
109-
Log.ServiceConfigurationNotFound(_logger, _serviceName, $"{_options.Value.SectionName}:{_serviceName}");
109+
Log.EndpointConfigurationNotFound(_logger, endpointName, _serviceName, configPath);
110110
return default;
111111
}
112112

@@ -170,6 +170,10 @@ public ValueTask ResolveAsync(ServiceEndPointCollectionSource endPoints, Cancell
170170
{
171171
Log.ServiceConfigurationNotFound(_logger, _serviceName, configPath);
172172
}
173+
else
174+
{
175+
Log.ConfiguredEndPoints(_logger, _serviceName, configPath, endPoints.EndPoints, added);
176+
}
173177

174178
return default;
175179
}

0 commit comments

Comments
 (0)