Browse Source

Remove string interpolation from logging

dotnet3-migration/dev-dotnet3
Miguel Veloso 5 years ago
parent
commit
866e89cad2
14 changed files with 25 additions and 25 deletions
  1. +2
    -2
      src/ApiGateways/Mobile.Bff.Shopping/aggregator/Services/GrpcCallerService.cs
  2. +2
    -2
      src/ApiGateways/Web.Bff.Shopping/aggregator/Services/GrpcCallerService.cs
  3. +2
    -2
      src/Services/Basket/Basket.API/Grpc/BasketService.cs
  4. +1
    -1
      src/Services/Basket/Basket.API/Infrastructure/Middlewares/FailingMiddleware.cs
  5. +1
    -1
      src/Services/Catalog/Catalog.API/Grpc/CatalogService.cs
  6. +2
    -2
      src/Services/Identity/Identity.API/Devspaces/DevspacesRedirectUriValidator.cs
  7. +1
    -1
      src/Services/Ordering/Ordering.API/Grpc/OrderingService.cs
  8. +1
    -1
      src/Services/Webhooks/Webhooks.API/IntegrationEvents/OrderStatusChangedToPaidIntegrationEventHandler.cs
  9. +1
    -1
      src/Services/Webhooks/Webhooks.API/IntegrationEvents/OrderStatusChangedToShippedIntegrationEventHandler.cs
  10. +4
    -4
      src/Services/Webhooks/Webhooks.API/Services/GrantUrlTesterService.cs
  11. +1
    -1
      src/Services/Webhooks/Webhooks.API/Services/WebhooksSender.cs
  12. +1
    -1
      src/Services/Webhooks/Webhooks.API/Startup.cs
  13. +2
    -2
      src/Web/WebMVC/Services/BasketService.cs
  14. +4
    -4
      src/Web/WebhookClient/Controllers/WebhooksReceivedController.cs

+ 2
- 2
src/ApiGateways/Mobile.Bff.Shopping/aggregator/Services/GrpcCallerService.cs View File

@ -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
{


+ 2
- 2
src/ApiGateways/Web.Bff.Shopping/aggregator/Services/GrpcCallerService.cs View File

@ -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
{


+ 2
- 2
src/Services/Basket/Basket.API/Grpc/BasketService.cs View File

@ -22,7 +22,7 @@ namespace GrpcBasket
[AllowAnonymous]
public override async Task<CustomerBasketResponse> 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<CustomerBasketResponse> 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);


+ 1
- 1
src/Services/Basket/Basket.API/Infrastructure/Middlewares/FailingMiddleware.cs View File

@ -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.");


+ 1
- 1
src/Services/Catalog/Catalog.API/Grpc/CatalogService.cs View File

@ -29,7 +29,7 @@ namespace Catalog.API.Grpc
public override async Task<CatalogItemResponse> 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})");


+ 2
- 2
src/Services/Identity/Identity.API/Devspaces/DevspacesRedirectUriValidator.cs View File

@ -17,13 +17,13 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API.Devspaces
public Task<bool> 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<bool> 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);
}


+ 1
- 1
src/Services/Ordering/Ordering.API/Grpc/OrderingService.cs View File

@ -26,7 +26,7 @@ namespace GrpcOrdering
public override async Task<OrderDraftDTO> 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(),


+ 1
- 1
src/Services/Webhooks/Webhooks.API/IntegrationEvents/OrderStatusChangedToPaidIntegrationEventHandler.cs View File

@ -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);
}


+ 1
- 1
src/Services/Webhooks/Webhooks.API/IntegrationEvents/OrderStatusChangedToShippedIntegrationEventHandler.cs View File

@ -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);
}


+ 4
- 4
src/Services/Webhooks/Webhooks.API/Services/GrantUrlTesterService.cs View File

@ -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;
}
}


+ 1
- 1
src/Services/Webhooks/Webhooks.API/Services/WebhooksSender.cs View File

@ -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);
}


+ 1
- 1
src/Services/Webhooks/Webhooks.API/Startup.cs View File

@ -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);
}


+ 2
- 2
src/Web/WebMVC/Services/BasketService.cs View File

@ -32,9 +32,9 @@ namespace Microsoft.eShopOnContainers.WebMVC.Services
public async Task<Basket> 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 } :


+ 4
- 4
src/Web/WebhookClient/Controllers/WebhooksReceivedController.cs View File

@ -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();
}
}


Loading…
Cancel
Save