From 378b90b57051316f2a23059d29026e1dcfb9e25a Mon Sep 17 00:00:00 2001 From: Chris Price Date: Mon, 26 Sep 2022 15:15:05 -0700 Subject: [PATCH] fix: remove Console.WriteLine statements and replace with logging (#188) * fix: remove Console.WriteLine statements and replace with logging --- .../Config/Middleware/LoggingMiddleware.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Momento.Sdk/Config/Middleware/LoggingMiddleware.cs b/src/Momento.Sdk/Config/Middleware/LoggingMiddleware.cs index 0caa92f2..9bb00f6b 100644 --- a/src/Momento.Sdk/Config/Middleware/LoggingMiddleware.cs +++ b/src/Momento.Sdk/Config/Middleware/LoggingMiddleware.cs @@ -2,11 +2,22 @@ using Grpc.Core; using System.Threading.Tasks; using Grpc.Core.Interceptors; +using Microsoft.Extensions.Logging; namespace Momento.Sdk.Config.Middleware { + /// + /// Basic middleware that logs at debug level for each request/response. This + /// is mostly provided as an example of how to implement middlewares. + /// public class LoggingMiddleware : IMiddleware { + private readonly ILogger _logger; + + public LoggingMiddleware(ILoggerFactory loggerFactory) + { + _logger = loggerFactory.CreateLogger(); + } public async Task> WrapRequest( TRequest request, @@ -14,13 +25,12 @@ public async Task> WrapRequest>> continuation ) { - Console.WriteLine($"LOGGING MIDDLEWARE WRAPPING REQUEST: {request.GetType()}"); + _logger.LogDebug("Executing request of type: {}", request?.GetType()); var nextState = await continuation(request, callOptions); - Console.WriteLine($"LOGGING MIDDLEWARE WRAPPED REQUEST: {request.GetType()}"); return new MiddlewareResponseState( ResponseAsync: nextState.ResponseAsync.ContinueWith(r => { - Console.WriteLine($"LOGGING MIDDLEWARE RESPONSE CALLBACK: {request.GetType()}"); + _logger.LogDebug("Got response for request of type: {}", request?.GetType()); return r.Result; }), ResponseHeadersAsync: nextState.ResponseHeadersAsync,