From 866e89cad20f59746aa91e4c72de7b5b51443041 Mon Sep 17 00:00:00 2001 From: Miguel Veloso Date: Fri, 8 Nov 2019 15:15:15 +0000 Subject: [PATCH] Remove string interpolation from logging --- .../aggregator/Services/GrpcCallerService.cs | 4 ++-- .../aggregator/Services/GrpcCallerService.cs | 4 ++-- src/Services/Basket/Basket.API/Grpc/BasketService.cs | 4 ++-- .../Infrastructure/Middlewares/FailingMiddleware.cs | 2 +- src/Services/Catalog/Catalog.API/Grpc/CatalogService.cs | 2 +- .../Devspaces/DevspacesRedirectUriValidator.cs | 4 ++-- .../Ordering/Ordering.API/Grpc/OrderingService.cs | 2 +- .../OrderStatusChangedToPaidIntegrationEventHandler.cs | 2 +- .../OrderStatusChangedToShippedIntegrationEventHandler.cs | 2 +- .../Webhooks.API/Services/GrantUrlTesterService.cs | 8 ++++---- .../Webhooks/Webhooks.API/Services/WebhooksSender.cs | 2 +- src/Services/Webhooks/Webhooks.API/Startup.cs | 2 +- src/Web/WebMVC/Services/BasketService.cs | 4 ++-- .../Controllers/WebhooksReceivedController.cs | 8 ++++---- 14 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Services/GrpcCallerService.cs b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Services/GrpcCallerService.cs index 72ad91daa..fe857c6cc 100644 --- a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Services/GrpcCallerService.cs +++ b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Services/GrpcCallerService.cs @@ -33,7 +33,7 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services } catch (RpcException e) { - Log.Error($"Error calling via grpc: {e.Status} - {e.Message}"); + Log.Error("Error calling via grpc: {Status} - {Message}", e.Status, e.Message); return default; } finally @@ -65,7 +65,7 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services } catch (RpcException e) { - Log.Error($"Error calling via grpc: {e.Status} - {e.Message}"); + Log.Error("Error calling via grpc: {Status} - {Message}", e.Status, e.Message); } finally { diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/GrpcCallerService.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/GrpcCallerService.cs index 68d096ce5..43138f987 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/GrpcCallerService.cs +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/GrpcCallerService.cs @@ -32,7 +32,7 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services } catch (RpcException e) { - Log.Error($"Error calling via grpc: {e.Status} - {e.Message}"); + Log.Error("Error calling via grpc: {Status} - {Message}", e.Status, e.Message); return default; } finally @@ -66,7 +66,7 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services } catch (RpcException e) { - Log.Error($"Error calling via grpc: {e.Status} - {e.Message}"); + Log.Error("Error calling via grpc: {Status} - {Message}", e.Status, e.Message); } finally { diff --git a/src/Services/Basket/Basket.API/Grpc/BasketService.cs b/src/Services/Basket/Basket.API/Grpc/BasketService.cs index e92190c73..830703b59 100644 --- a/src/Services/Basket/Basket.API/Grpc/BasketService.cs +++ b/src/Services/Basket/Basket.API/Grpc/BasketService.cs @@ -22,7 +22,7 @@ namespace GrpcBasket [AllowAnonymous] public override async Task GetBasketById(BasketRequest request, ServerCallContext context) { - _logger.LogInformation($"Begin grpc call from method {context.Method} for basket id {request.Id}"); + _logger.LogInformation("Begin grpc call from method {Method} for basket id {Id}", context.Method, request.Id); var data = await _repository.GetBasketAsync(request.Id); @@ -42,7 +42,7 @@ namespace GrpcBasket public override async Task UpdateBasket(CustomerBasketRequest request, ServerCallContext context) { - _logger.LogInformation($"Begin grpc call BasketService.UpdateBasketAsync for buyer id {request.Buyerid}"); + _logger.LogInformation("Begin grpc call BasketService.UpdateBasketAsync for buyer id {Buyerid}", request.Buyerid); var customerBasket = MapToCustomerBasket(request); diff --git a/src/Services/Basket/Basket.API/Infrastructure/Middlewares/FailingMiddleware.cs b/src/Services/Basket/Basket.API/Infrastructure/Middlewares/FailingMiddleware.cs index 852c61d1f..108955bd4 100644 --- a/src/Services/Basket/Basket.API/Infrastructure/Middlewares/FailingMiddleware.cs +++ b/src/Services/Basket/Basket.API/Infrastructure/Middlewares/FailingMiddleware.cs @@ -30,7 +30,7 @@ namespace Basket.API.Infrastructure.Middlewares if (MustFail(context)) { - _logger.LogInformation($"Response for path {path} will fail."); + _logger.LogInformation("Response for path {Path} will fail.", path); context.Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError; context.Response.ContentType = "text/plain"; await context.Response.WriteAsync("Failed due to FailingMiddleware enabled."); diff --git a/src/Services/Catalog/Catalog.API/Grpc/CatalogService.cs b/src/Services/Catalog/Catalog.API/Grpc/CatalogService.cs index 39d7828c2..13c7c8d2e 100644 --- a/src/Services/Catalog/Catalog.API/Grpc/CatalogService.cs +++ b/src/Services/Catalog/Catalog.API/Grpc/CatalogService.cs @@ -29,7 +29,7 @@ namespace Catalog.API.Grpc public override async Task GetItemById(CatalogItemRequest request, ServerCallContext context) { - _logger.LogInformation($"Begin grpc call CatalogService.GetItemById for product id {request.Id}"); + _logger.LogInformation("Begin grpc call CatalogService.GetItemById for product id {Id}", request.Id); if (request.Id <= 0) { context.Status = new Status(StatusCode.FailedPrecondition, $"Id must be > 0 (received {request.Id})"); diff --git a/src/Services/Identity/Identity.API/Devspaces/DevspacesRedirectUriValidator.cs b/src/Services/Identity/Identity.API/Devspaces/DevspacesRedirectUriValidator.cs index 53e497b59..d43a9ab15 100644 --- a/src/Services/Identity/Identity.API/Devspaces/DevspacesRedirectUriValidator.cs +++ b/src/Services/Identity/Identity.API/Devspaces/DevspacesRedirectUriValidator.cs @@ -17,13 +17,13 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API.Devspaces public Task IsPostLogoutRedirectUriValidAsync(string requestedUri, Client client) { - _logger.LogInformation($"Client {client.ClientName} used post logout uri {requestedUri}."); + _logger.LogInformation("Client {ClientName} used post logout uri {RequestedUri}.", client.ClientName, requestedUri); return Task.FromResult(true); } public Task IsRedirectUriValidAsync(string requestedUri, Client client) { - _logger.LogInformation($"Client {client.ClientName} used redirect uri {requestedUri}."); + _logger.LogInformation("Client {ClientName} used post logout uri {RequestedUri}.", client.ClientName, requestedUri); return Task.FromResult(true); } diff --git a/src/Services/Ordering/Ordering.API/Grpc/OrderingService.cs b/src/Services/Ordering/Ordering.API/Grpc/OrderingService.cs index adc210a1a..5effedc1d 100644 --- a/src/Services/Ordering/Ordering.API/Grpc/OrderingService.cs +++ b/src/Services/Ordering/Ordering.API/Grpc/OrderingService.cs @@ -26,7 +26,7 @@ namespace GrpcOrdering public override async Task CreateOrderDraftFromBasketData(CreateOrderDraftCommand createOrderDraftCommand, ServerCallContext context) { - _logger.LogInformation($"Begin grpc call from method {context.Method} for ordering get order draft {createOrderDraftCommand}"); + _logger.LogInformation("Begin grpc call from method {Method} for ordering get order draft {CreateOrderDraftCommand}", context.Method, createOrderDraftCommand); _logger.LogTrace( "----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})", createOrderDraftCommand.GetGenericTypeName(), diff --git a/src/Services/Webhooks/Webhooks.API/IntegrationEvents/OrderStatusChangedToPaidIntegrationEventHandler.cs b/src/Services/Webhooks/Webhooks.API/IntegrationEvents/OrderStatusChangedToPaidIntegrationEventHandler.cs index 2503bdca7..0b118bb61 100644 --- a/src/Services/Webhooks/Webhooks.API/IntegrationEvents/OrderStatusChangedToPaidIntegrationEventHandler.cs +++ b/src/Services/Webhooks/Webhooks.API/IntegrationEvents/OrderStatusChangedToPaidIntegrationEventHandler.cs @@ -24,7 +24,7 @@ namespace Webhooks.API.IntegrationEvents public async Task Handle(OrderStatusChangedToPaidIntegrationEvent @event) { var subscriptions = await _retriever.GetSubscriptionsOfType(WebhookType.OrderPaid); - _logger.LogInformation($"Received OrderStatusChangedToShippedIntegrationEvent and got {subscriptions.Count()} subscriptions to process"); + _logger.LogInformation("Received OrderStatusChangedToShippedIntegrationEvent and got {SubscriptionsCount} subscriptions to process", subscriptions.Count()); var whook = new WebhookData(WebhookType.OrderPaid, @event); await _sender.SendAll(subscriptions, whook); } diff --git a/src/Services/Webhooks/Webhooks.API/IntegrationEvents/OrderStatusChangedToShippedIntegrationEventHandler.cs b/src/Services/Webhooks/Webhooks.API/IntegrationEvents/OrderStatusChangedToShippedIntegrationEventHandler.cs index 9a1dea33d..9e2325d91 100644 --- a/src/Services/Webhooks/Webhooks.API/IntegrationEvents/OrderStatusChangedToShippedIntegrationEventHandler.cs +++ b/src/Services/Webhooks/Webhooks.API/IntegrationEvents/OrderStatusChangedToShippedIntegrationEventHandler.cs @@ -24,7 +24,7 @@ namespace Webhooks.API.IntegrationEvents public async Task Handle(OrderStatusChangedToShippedIntegrationEvent @event) { var subscriptions = await _retriever.GetSubscriptionsOfType(WebhookType.OrderShipped); - _logger.LogInformation($"Received OrderStatusChangedToShippedIntegrationEvent and got {subscriptions.Count()} subscriptions to process"); + _logger.LogInformation("Received OrderStatusChangedToShippedIntegrationEvent and got {SubscriptionCount} subscriptions to process", subscriptions.Count()); var whook = new WebhookData(WebhookType.OrderShipped, @event); await _sender.SendAll(subscriptions, whook); } diff --git a/src/Services/Webhooks/Webhooks.API/Services/GrantUrlTesterService.cs b/src/Services/Webhooks/Webhooks.API/Services/GrantUrlTesterService.cs index c4b38b724..fef390dda 100644 --- a/src/Services/Webhooks/Webhooks.API/Services/GrantUrlTesterService.cs +++ b/src/Services/Webhooks/Webhooks.API/Services/GrantUrlTesterService.cs @@ -20,7 +20,7 @@ namespace Webhooks.API.Services { if (!CheckSameOrigin(urlHook, url)) { - _logger.LogWarning($"Url of the hook ({urlHook} and the grant url ({url} do not belong to same origin)"); + _logger.LogWarning("Url of the hook ({UrlHook} and the grant url ({Url} do not belong to same origin)", urlHook, url); return false; } @@ -28,18 +28,18 @@ namespace Webhooks.API.Services var client = _clientFactory.CreateClient("GrantClient"); var msg = new HttpRequestMessage(HttpMethod.Options, url); msg.Headers.Add("X-eshop-whtoken", token); - _logger.LogInformation($"Sending the OPTIONS message to {url} with token {token ?? string.Empty}"); + _logger.LogInformation("Sending the OPTIONS message to {Url} with token \"{Token}\"", url, token ?? string.Empty); try { var response = await client.SendAsync(msg); var tokenReceived = response.Headers.TryGetValues("X-eshop-whtoken", out var tokenValues) ? tokenValues.FirstOrDefault() : null; var tokenExpected = string.IsNullOrWhiteSpace(token) ? null : token; - _logger.LogInformation($"Response code is {response.StatusCode} for url {url} and token in header was {tokenReceived} (expected token was {tokenExpected})"); + _logger.LogInformation("Response code is {StatusCode} for url {Url} and token in header was {TokenReceived} (expected token was {TokenExpected})", response.StatusCode, url, tokenReceived, tokenExpected); return response.IsSuccessStatusCode && tokenReceived == tokenExpected; } catch (Exception ex) { - _logger.LogWarning($"Exception {ex.GetType().Name} when sending OPTIONS request. Url can't be granted."); + _logger.LogWarning("Exception {TypeName} when sending OPTIONS request. Url can't be granted.", ex.GetType().Name); return false; } } diff --git a/src/Services/Webhooks/Webhooks.API/Services/WebhooksSender.cs b/src/Services/Webhooks/Webhooks.API/Services/WebhooksSender.cs index 62128411c..7ab7a0c67 100644 --- a/src/Services/Webhooks/Webhooks.API/Services/WebhooksSender.cs +++ b/src/Services/Webhooks/Webhooks.API/Services/WebhooksSender.cs @@ -41,7 +41,7 @@ namespace Webhooks.API.Services { request.Headers.Add("X-eshop-whtoken", subs.Token); } - _logger.LogDebug($"Sending hook to {subs.DestUrl} of type {subs.Type.ToString()}"); + _logger.LogDebug("Sending hook to {DestUrl} of type {Type}", subs.Type.ToString(), subs.Type.ToString()); return client.SendAsync(request); } diff --git a/src/Services/Webhooks/Webhooks.API/Startup.cs b/src/Services/Webhooks/Webhooks.API/Startup.cs index 5859e9e12..07872a58b 100644 --- a/src/Services/Webhooks/Webhooks.API/Startup.cs +++ b/src/Services/Webhooks/Webhooks.API/Startup.cs @@ -74,7 +74,7 @@ namespace Webhooks.API if (!string.IsNullOrEmpty(pathBase)) { - loggerFactory.CreateLogger("init").LogDebug($"Using PATH BASE '{pathBase}'"); + loggerFactory.CreateLogger("init").LogDebug("Using PATH BASE '{PathBase}'", pathBase); app.UsePathBase(pathBase); } diff --git a/src/Web/WebMVC/Services/BasketService.cs b/src/Web/WebMVC/Services/BasketService.cs index 8e72ef249..64184f7b2 100644 --- a/src/Web/WebMVC/Services/BasketService.cs +++ b/src/Web/WebMVC/Services/BasketService.cs @@ -32,9 +32,9 @@ namespace Microsoft.eShopOnContainers.WebMVC.Services public async Task GetBasket(ApplicationUser user) { var uri = API.Basket.GetBasket(_basketByPassUrl, user.Id); - _logger.LogDebug($"[GetBasket] -> Calling {uri} to get the basket"); + _logger.LogDebug("[GetBasket] -> Calling {Uri} to get the basket", uri); var response = await _apiClient.GetAsync(uri); - _logger.LogDebug($"[GetBasket] -> response code {response.StatusCode}"); + _logger.LogDebug("[GetBasket] -> response code {StatusCode}", response.StatusCode); var responseString = await response.Content.ReadAsStringAsync(); return string.IsNullOrEmpty(responseString) ? new Basket() { BuyerId = user.Id } : diff --git a/src/Web/WebhookClient/Controllers/WebhooksReceivedController.cs b/src/Web/WebhookClient/Controllers/WebhooksReceivedController.cs index 5f1f793c8..7746b6059 100644 --- a/src/Web/WebhookClient/Controllers/WebhooksReceivedController.cs +++ b/src/Web/WebhookClient/Controllers/WebhooksReceivedController.cs @@ -33,11 +33,11 @@ namespace WebhookClient.Controllers var header = Request.Headers[HeaderNames.WebHookCheckHeader]; var token = header.FirstOrDefault(); - _logger.LogInformation($"Received hook with token {token}. My token is {_settings.Token}. Token validation is set to {_settings.ValidateToken}"); + _logger.LogInformation("Received hook with token {Token}. My token is {MyToken}. Token validation is set to {ValidateToken}", token, _settings.Token, _settings.ValidateToken); if (!_settings.ValidateToken || _settings.Token == token) { - _logger.LogInformation($"Received hook is going to be processed"); + _logger.LogInformation("Received hook is going to be processed"); var newHook = new WebHookReceived() { Data = hook.Payload, @@ -45,11 +45,11 @@ namespace WebhookClient.Controllers Token = token }; await _hooksRepository.AddNew(newHook); - _logger.LogInformation($"Received hook was processed."); + _logger.LogInformation("Received hook was processed."); return Ok(newHook); } - _logger.LogInformation($"Received hook is NOT processed - Bad Request returned."); + _logger.LogInformation("Received hook is NOT processed - Bad Request returned."); return BadRequest(); } }