Skip to content

Commit

Permalink
Reduce logger allocations by not using generic CreateLogger (#2256)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNK committed Aug 26, 2023
1 parent 3db1683 commit 6429ae2
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Grpc.Net.Client/Balancer/DnsResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public DnsResolver(Uri address, int defaultPort, ILoggerFactory loggerFactory, T
_dnsAddress = addressParsed.Host;
_port = addressParsed.Port == -1 ? defaultPort : addressParsed.Port;
_refreshInterval = refreshInterval;
_logger = loggerFactory.CreateLogger<DnsResolver>();
_logger = loggerFactory.CreateLogger(typeof(DnsResolver));
}

protected override void OnStarted()
Expand Down
4 changes: 2 additions & 2 deletions src/Grpc.Net.Client/Balancer/Internal/BalancerHttpHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region Copyright notice and license
#region Copyright notice and license

// Copyright 2019 The gRPC Authors
//
Expand Down Expand Up @@ -45,7 +45,7 @@ public BalancerHttpHandler(HttpMessageHandler innerHandler, ConnectionManager ma
: base(innerHandler)
{
_manager = manager;
_logger = manager.LoggerFactory.CreateLogger<BalancerHttpHandler>();
_logger = manager.LoggerFactory.CreateLogger(typeof(BalancerHttpHandler));
}

internal static bool IsSocketsHttpHandlerSetup(SocketsHttpHandler socketsHttpHandler)
Expand Down
2 changes: 1 addition & 1 deletion src/Grpc.Net.Client/Balancer/Internal/ConnectionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ internal ConnectionManager(
_resolverStartedTcs = new TaskCompletionSource<object?>(TaskCreationOptions.RunContinuationsAsynchronously);
_channelId = _channelIdProvider.GetNextChannelId();

Logger = loggerFactory.CreateLogger<ConnectionManager>();
Logger = loggerFactory.CreateLogger(typeof(ConnectionManager));
LoggerFactory = loggerFactory;
BackoffPolicyFactory = backoffPolicyFactory;
_subchannels = new List<Subchannel>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public SocketConnectivitySubchannelTransport(
ILoggerFactory loggerFactory,
Func<Socket, DnsEndPoint, CancellationToken, ValueTask>? socketConnect)
{
_logger = loggerFactory.CreateLogger<SocketConnectivitySubchannelTransport>();
_logger = loggerFactory.CreateLogger(typeof(SocketConnectivitySubchannelTransport));
_subchannel = subchannel;
_socketPingInterval = socketPingInterval;
ConnectTimeout = connectTimeout;
Expand Down
2 changes: 1 addition & 1 deletion src/Grpc.Net.Client/Balancer/PickFirstBalancer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ internal sealed class PickFirstBalancer : LoadBalancer
public PickFirstBalancer(IChannelControlHelper controller, ILoggerFactory loggerFactory)
{
_controller = controller;
_logger = loggerFactory.CreateLogger<PickFirstBalancer>();
_logger = loggerFactory.CreateLogger(typeof(PickFirstBalancer));
}

private void ResolverError(Status status)
Expand Down
2 changes: 1 addition & 1 deletion src/Grpc.Net.Client/Balancer/PollingResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected PollingResolver(ILoggerFactory loggerFactory, IBackoffPolicyFactory? b
{
ArgumentNullThrowHelper.ThrowIfNull(loggerFactory);

_logger = loggerFactory.CreateLogger<PollingResolver>();
_logger = loggerFactory.CreateLogger(typeof(PollingResolver));
_backoffPolicyFactory = backoffPolicyFactory;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Grpc.Net.Client/GrpcChannel.cs