-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add LoggerFactory to ChannelFactory (#531)
- Loading branch information
Showing
1 changed file
with
24 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// This file is part of the ArmoniK project | ||
// | ||
// Copyright (C) ANEO, 2021-2023. All rights reserved. | ||
// Copyright (C) ANEO, 2021-2024. All rights reserved. | ||
// W. Kirschenmann <[email protected]> | ||
// J. Gurhem <[email protected]> | ||
// D. Dubuc <[email protected]> | ||
|
@@ -261,13 +261,15 @@ private static SslProtocols GetSslProtocols() | |
/// <param name="optionsGrpcClient">Options for the creation of the channel</param> | ||
/// <param name="handlerType">Which HttpMessageHandler type to use</param> | ||
/// <param name="logger">Optional logger</param> | ||
/// <param name="loggerFactory">Optional loggerFactory</param> | ||
/// <returns> | ||
/// The initialized GrpcChannel | ||
/// </returns> | ||
/// <exception cref="InvalidOperationException">Endpoint passed through options is missing</exception> | ||
private static GrpcChannel CreateChannelInternal(GrpcClient optionsGrpcClient, | ||
HandlerType handlerType, | ||
ILogger? logger) | ||
private static GrpcChannel CreateChannelInternal(GrpcClient optionsGrpcClient, | ||
HandlerType handlerType, | ||
ILogger? logger, | ||
ILoggerFactory? loggerFactory) | ||
{ | ||
if (string.IsNullOrEmpty(optionsGrpcClient.Endpoint)) | ||
{ | ||
|
@@ -417,6 +419,7 @@ private static GrpcChannel CreateChannelInternal(GrpcClient optionsGrpcClient, | |
Credentials = credentials, | ||
DisposeHttpClient = true, | ||
ServiceConfig = serviceConfig, | ||
LoggerFactory = loggerFactory, | ||
}; | ||
|
||
if (handlerType is HandlerType.Web) | ||
|
@@ -439,29 +442,35 @@ private static GrpcChannel CreateChannelInternal(GrpcClient optionsGrpcClient, | |
/// </summary> | ||
/// <param name="optionsGrpcClient">Options for the creation of the channel</param> | ||
/// <param name="logger">Optional logger</param> | ||
/// <param name="loggerFactory">Optional loggerFactory</param> | ||
/// <param name="cancellationToken">Cancellation token</param> | ||
/// <returns> | ||
/// The initialized GrpcChannel | ||
/// </returns> | ||
/// <exception cref="InvalidOperationException">Endpoint passed through options is missing</exception> | ||
public static Task<GrpcChannel> CreateChannelAsync(GrpcClient optionsGrpcClient, | ||
ILogger? logger = null, | ||
ILoggerFactory? loggerFactory = null, | ||
CancellationToken cancellationToken = default) | ||
=> Task.FromResult(CreateChannel(optionsGrpcClient, | ||
logger)); | ||
logger, | ||
loggerFactory)); | ||
|
||
/// <summary> | ||
/// Creates the GrpcChannel | ||
/// </summary> | ||
/// <param name="optionsGrpcClient">Options for the creation of the channel</param> | ||
/// <param name="logger">Optional logger</param> | ||
/// <param name="loggerFactory">Optional loggerFactory</param> | ||
/// <returns> | ||
/// The initialized GrpcChannel | ||
/// </returns> | ||
/// <exception cref="InvalidOperationException">Endpoint passed through options is missing</exception> | ||
public static GrpcChannel CreateChannel(GrpcClient optionsGrpcClient, | ||
ILogger? logger = null) | ||
public static GrpcChannel CreateChannel(GrpcClient optionsGrpcClient, | ||
ILogger? logger = null, | ||
ILoggerFactory? loggerFactory = null) | ||
{ | ||
logger ??= loggerFactory?.CreateLogger<GrpcChannel>(); | ||
if (!string.IsNullOrEmpty(optionsGrpcClient.OverrideTargetName)) | ||
{ | ||
logger?.LogWarning("OverrideTargetName is not supported"); | ||
|
@@ -472,15 +481,17 @@ public static GrpcChannel CreateChannel(GrpcClient optionsGrpcClient, | |
{ | ||
return CreateChannelInternal(optionsGrpcClient, | ||
handlerType, | ||
logger); | ||
logger, | ||
loggerFactory); | ||
} | ||
|
||
// If dotnet core (>= Net 5), we can use HttpClientHandler | ||
if (!RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework")) | ||
{ | ||
return CreateChannelInternal(optionsGrpcClient, | ||
HandlerType.Http, | ||
logger); | ||
logger, | ||
loggerFactory); | ||
} | ||
|
||
// If dotnet framework, we can use a plain WinHttpHandler. | ||
|
@@ -489,7 +500,8 @@ public static GrpcChannel CreateChannel(GrpcClient optionsGrpcClient, | |
{ | ||
return CreateChannelInternal(optionsGrpcClient, | ||
HandlerType.Win, | ||
logger); | ||
logger, | ||
loggerFactory); | ||
} | ||
catch (InvalidOperationException e) | ||
{ | ||
|
@@ -499,7 +511,8 @@ public static GrpcChannel CreateChannel(GrpcClient optionsGrpcClient, | |
"Falling back to gRPC Web that does not fully support gRPC streams"); | ||
return CreateChannelInternal(optionsGrpcClient, | ||
HandlerType.Web, | ||
logger); | ||
logger, | ||
loggerFactory); | ||
} | ||
} | ||
|
||
|