Skip to content

Commit 8b628b5

Browse files
authored
Using log templates and removing period at end of log and exception message (#246)
* Using Log templates and removing period at end of log and exception messages * !fixup previous commit
1 parent 1f5d9c5 commit 8b628b5

13 files changed

Lines changed: 58 additions & 50 deletions

File tree

src/ServiceControl.Connector.MassTransit.AzureServiceBus/AzureServiceBusHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public async Task<long> GetQueueLength(string name, CancellationToken cancellati
4646
catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested) { }
4747
catch (UnauthorizedAccessException)
4848
{
49-
return (false, "The token has an invalid signature.");
49+
return (false, "The token has an invalid signature");
5050
}
5151
catch (Azure.RequestFailedException e)
5252
{

src/ServiceControl.Connector.MassTransit.Host/Commands/HealthCheckCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace ServiceControl.Connector.MassTransit.Host.Commands;
77

88
public class HealthCheckCommand : Command
99
{
10-
public HealthCheckCommand() : base("health-check", "Performs a validation that the connector is able to connect to the broker.")
10+
public HealthCheckCommand() : base("health-check", "Performs a validation that the connector is able to connect to the broker")
1111
{
1212
this.SetHandler(async context =>
1313
{

src/ServiceControl.Connector.MassTransit.Host/Commands/StartupCommand.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,14 @@ static void RecordStartup(Configuration settings, ILoggerFactory loggerFactory)
8484
{
8585
var logger = loggerFactory.CreateLogger("Diagnostics");
8686
logger.LogInformation("-------------------------------------------------------------------------------------------");
87-
logger.LogInformation($"Connector Version: {ConnectorVersion.Version}");
88-
logger.LogInformation($"Error Queue: {settings.ErrorQueue}");
89-
logger.LogInformation($"Service Control Queue: {settings.ServiceControlQueue}");
90-
logger.LogInformation($"Poison Queue: {settings.PoisonQueue}");
91-
logger.LogInformation($"Return Queue: {settings.ReturnQueue}");
92-
logger.LogInformation($"Queue Scan Interval: {settings.QueueScanInterval}");
93-
logger.LogInformation($"Custom Checks Interval: {settings.CustomChecksInterval}");
94-
logger.LogInformation($"Heartbeat Interval: {settings.HeartbeatInterval}");
87+
logger.LogInformation("Connector Version: {Version}", ConnectorVersion.Version);
88+
logger.LogInformation("Error Queue: {ErrorQueue}", settings.ErrorQueue);
89+
logger.LogInformation("Service Control Queue: {ServiceControlQueue}", settings.ServiceControlQueue);
90+
logger.LogInformation("Poison Queue: {PoisonQueue}", settings.PoisonQueue);
91+
logger.LogInformation("Return Queue: {ReturnQueue}", settings.ReturnQueue);
92+
logger.LogInformation("Queue Scan Interval: {QueueScanInterval}", settings.QueueScanInterval);
93+
logger.LogInformation("Custom Checks Interval: {CustomChecksInterval}", settings.CustomChecksInterval);
94+
logger.LogInformation("Heartbeat Interval: {HeartbeatInterval}", settings.HeartbeatInterval);
9595
logger.LogInformation("-------------------------------------------------------------------------------------------");
9696
}
9797
}

src/ServiceControl.Connector.MassTransit.Host/HostApplicationBuilderExtensions.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static void UseMassTransitConnector(this HostApplicationBuilder builder,
4242

4343
if (!File.Exists(staticQueueList))
4444
{
45-
throw new Exception($"Queues file ({staticQueueList}) specified does not exist.");
45+
throw new Exception($"Queues file ({staticQueueList}) specified does not exist");
4646
}
4747

4848
var content = File.ReadAllText(staticQueueList);
@@ -72,7 +72,7 @@ public static void UseMassTransitConnector(this HostApplicationBuilder builder,
7272
}
7373
catch (Exception)
7474
{
75-
throw new Exception("CONNECTION_STRING environment variable contains an invalid connection string. Please check the value and try again.");
75+
throw new Exception("CONNECTION_STRING environment variable contains an invalid connection string. Please check the value and try again");
7676
}
7777
}
7878

@@ -83,22 +83,22 @@ public static void UseMassTransitConnector(this HostApplicationBuilder builder,
8383
break;
8484
case "AzureServiceBus":
8585
services.UsingAzureServiceBus(configuration,
86-
connectionString ?? throw new Exception("CONNECTION_STRING environment variable not set."));
86+
connectionString ?? throw new Exception("CONNECTION_STRING environment variable not set"));
8787
break;
8888
case "AzureServiceBusWithDeadLetter":
8989
services.UsingAzureServiceBus(configuration,
90-
connectionString ?? throw new Exception("CONNECTION_STRING environment variable not set."), true);
90+
connectionString ?? throw new Exception("CONNECTION_STRING environment variable not set"), true);
9191
break;
9292
case "RabbitMQ":
93-
var managementApiValue = configuration.GetValue<string>("RABBITMQ_MANAGEMENT_API_URL") ?? throw new Exception("RABBITMQ_MANAGEMENT_API_URL environment variable not set.");
93+
var managementApiValue = configuration.GetValue<string>("RABBITMQ_MANAGEMENT_API_URL") ?? throw new Exception("RABBITMQ_MANAGEMENT_API_URL environment variable not set");
9494
if (!Uri.TryCreate(managementApiValue, UriKind.Absolute, out var managementApi))
9595
{
96-
throw new Exception("RABBITMQ_MANAGEMENT_API_URL is invalid. Ensure the value is a valid url without any quotes e.g. http://localhost:15672.");
96+
throw new Exception("RABBITMQ_MANAGEMENT_API_URL is invalid. Ensure the value is a valid url without any quotes e.g. http://localhost:15672");
9797
}
98-
services.UsingRabbitMQ(connectionString ?? throw new Exception("CONNECTION_STRING environment variable not set."), managementApi, configuration.GetValue<string>("RABBITMQ_MANAGEMENT_API_USERNAME"), configuration.GetValue<string>("RABBITMQ_MANAGEMENT_API_PASSWORD"));
98+
services.UsingRabbitMQ(connectionString ?? throw new Exception("CONNECTION_STRING environment variable not set"), managementApi, configuration.GetValue<string>("RABBITMQ_MANAGEMENT_API_USERNAME"), configuration.GetValue<string>("RABBITMQ_MANAGEMENT_API_PASSWORD"));
9999
break;
100100
default:
101-
throw new NotSupportedException($"TRANSPORT_TYPE environment variable specified has an invalid value ({transportType}). Please use one of the following: AzureServiceBus, AzureServiceBusWithDeadLetter, RabbitMQ.");
101+
throw new NotSupportedException($"TRANSPORT_TYPE environment variable specified has an invalid value ({transportType}). Please use one of the following: AzureServiceBus, AzureServiceBusWithDeadLetter, RabbitMQ");
102102
}
103103

104104
services.AddSingleton<IFileBasedQueueInformationProvider>(new FileBasedQueueInformationProvider(staticQueueList));

src/ServiceControl.Connector.MassTransit.RabbitMQ/AdapterRabbitMqConfiguration.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ static Dictionary<string, string> ParseNServiceBusConnectionString(string connec
220220

221221
if (dictionary.TryGetValue("port", out var portValue) && !int.TryParse(portValue, out var port))
222222
{
223-
invalidOptionsMessage.AppendLine($"'{portValue}' is not a valid Int32 value for the 'port' connection string option.");
223+
invalidOptionsMessage.AppendLine($"'{portValue}' is not a valid Int32 value for the 'port' connection string option");
224224
}
225225

226226
if (dictionary.TryGetValue("host", out var value))
@@ -231,7 +231,7 @@ static Dictionary<string, string> ParseNServiceBusConnectionString(string connec
231231

232232
if (host.Length == 0)
233233
{
234-
invalidOptionsMessage.AppendLine("Empty host name in 'host' connection string option.");
234+
invalidOptionsMessage.AppendLine("Empty host name in 'host' connection string option");
235235
}
236236

237237
dictionary["host"] = host;
@@ -240,7 +240,7 @@ static Dictionary<string, string> ParseNServiceBusConnectionString(string connec
240240
{
241241
if (!int.TryParse(parts[1], out port))
242242
{
243-
invalidOptionsMessage.AppendLine($"'{parts[1]}' is not a valid Int32 value for the port in the 'host' connection string option.");
243+
invalidOptionsMessage.AppendLine($"'{parts[1]}' is not a valid Int32 value for the port in the 'host' connection string option");
244244
}
245245
else
246246
{

src/ServiceControl.Connector.MassTransit.RabbitMQ/RabbitMQHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public async IAsyncEnumerable<string> GetQueues([EnumeratorCancellation] Cancell
5555
return (MaterializeQueueDetails(arr), false);
5656
}
5757
default:
58-
throw new Exception("Was not able to get list of queues from RabbitMQ broker.");
58+
throw new Exception("Was not able to get list of queues from RabbitMQ broker");
5959
}
6060
}
6161

@@ -102,7 +102,7 @@ public async Task<long> GetQueueLength(string queueName, CancellationToken cance
102102
}
103103
catch (Exception e)
104104
{
105-
throw new Exception($"Failed to check the length of the queue {queueName} via URL {url}.", e);
105+
throw new Exception($"Failed to check the length of the queue {queueName} via URL {url}", e);
106106
}
107107
}
108108

src/ServiceControl.Connector.MassTransit/Heartbeat.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ DiagnosticsData diagnosticsData
1515
{
1616
protected override async Task ExecuteAsync(CancellationToken cancellationToken)
1717
{
18-
logger.LogInformation($"Starting {nameof(Heartbeat)}.");
18+
logger.LogInformation("Starting {HeartbeatName}", nameof(Heartbeat));
1919

2020
var endpointConfiguration = new EndpointConfiguration(nameof(Heartbeat));
2121
endpointConfiguration.UseSerialization<SystemJsonSerializer>();
@@ -58,7 +58,7 @@ await endpointInstance.Send(
5858
}
5959
catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
6060
{
61-
logger.LogInformation($"Stopping {nameof(Heartbeat)}");
61+
logger.LogInformation("Stopping {HeartbeatName}", nameof(Heartbeat));
6262
}
6363
finally
6464
{

src/ServiceControl.Connector.MassTransit/MassTransitConverter.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public void From(MessageContext messageContext)
9292
}
9393
else
9494
{
95-
logger.LogWarning($"Using {MessageHeaders.FaultTimestamp} as fallback for missing {MessageHeaders.TransportSentTime}");
95+
logger.LogWarning("Using {FaultTimestamp} as fallback for missing header {HeaderKey}", MessageHeaders.FaultTimestamp, MessageHeaders.TransportSentTime);
9696
// Using time of failure as fallback
9797
var faultTimestampFallback = headers[MessageHeaders.FaultTimestamp];
9898
headers[NsbHeaders.TimeSent] = DateTimeOffsetHelper.ToWireFormattedString(DateTime.Parse(faultTimestampFallback));
@@ -135,9 +135,17 @@ public void From(MessageContext messageContext)
135135
// TODO: Getting the fault address this way should NOT be an alternate flow but be a the primary based on some setting
136136
// If this is a DLQ the input address is inferred from the queue it self
137137
faultInputAddress = messageContext.ReceiveAddress;
138-
logger.LogWarning($"Using `messageContext.ReceiveAddress` for {NsbHeaders.ProcessingEndpoint} as fallback for missing {MessageHeaders.FaultInputAddress}");
138+
logger.LogWarning("Using `{ReceiveAddress}` for {HeaderKey} as fallback for missing header {FaultInputAddress}",
139+
messageContext.ReceiveAddress,
140+
NsbHeaders.ProcessingEndpoint,
141+
MessageHeaders.FaultInputAddress
142+
);
139143
headers[NsbHeaders.ProcessingEndpoint] = faultInputAddress;
140-
logger.LogWarning($"Using `messageContext.ReceiveAddress` for {FaultsHeaderKeys.FailedQ} as fallback for missing {MessageHeaders.FaultInputAddress}");
144+
logger.LogWarning("Using `{ReceiveAddress}` for {HeaderKey} as fallback for missing header {FaultInputAddress}",
145+
messageContext.ReceiveAddress,
146+
FaultsHeaderKeys.FailedQ,
147+
MessageHeaders.FaultInputAddress
148+
);
141149
headers[MessageHeaders.FaultInputAddress] = "queue:" + faultInputAddress;
142150
headers[FaultsHeaderKeys.FailedQ] = faultInputAddress;
143151
}
@@ -169,7 +177,7 @@ public void From(MessageContext messageContext)
169177
else
170178
{
171179
// TODO: Not sure on this, maybe there is a better source
172-
logger.LogWarning($"Using current time for {FaultsHeaderKeys.TimeOfFailure} as fallback for missing {MessageHeaders.FaultTimestamp}");
180+
logger.LogWarning($"Using current time for {FaultsHeaderKeys.TimeOfFailure} as fallback for missing {MessageHeaders.FaultTimestamp}"); // Fixed values
173181
headers[FaultsHeaderKeys.TimeOfFailure] = DateTimeOffsetHelper.ToWireFormattedString(DateTimeOffset.UtcNow);
174182
}
175183

src/ServiceControl.Connector.MassTransit/MassTransitFailureAdapter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public virtual TransportOperation ReturnMassTransitFailure(MessageContext messag
5252

5353
if (!headers.TryGetValue(TargetEndpointAddress, out var targetEndpointAddress))
5454
{
55-
throw new InvalidOperationException($"Header '{TargetEndpointAddress}' is not set.");
55+
throw new InvalidOperationException($"Header '{TargetEndpointAddress}' is not set");
5656
}
5757

5858
string originalQueue;
@@ -69,7 +69,7 @@ public virtual TransportOperation ReturnMassTransitFailure(MessageContext messag
6969
originalQueue = targetEndpointAddress;
7070
}
7171

72-
logger.LogInformation("Forwarding failure with {NativeMessageId} native message id from {FaultInputAddress} back to original MassTransit queue {MassTransitQueue}.", messageContext.NativeMessageId, targetEndpointAddress, originalQueue);
72+
logger.LogInformation("Forwarding failure with {NativeMessageId} native message id from {FaultInputAddress} back to original MassTransit queue {MassTransitQueue}", messageContext.NativeMessageId, targetEndpointAddress, originalQueue);
7373

7474
messageContext.Headers.TryGetValue(Headers.ContentType, out var contentType);
7575

@@ -98,7 +98,7 @@ protected virtual void PatchAckQueue(TransportOperation operation)
9898
var h = operation.Message.Headers;
9999
if (!h.TryGetValue(RetryConfirmationQueueHeaderKey, out var ackQueue))
100100
{
101-
throw new InvalidOperationException($"Messages is expected to have '{RetryConfirmationQueueHeaderKey}' header.");
101+
throw new InvalidOperationException($"Message is expected to have '{RetryConfirmationQueueHeaderKey}' header");
102102
}
103103

104104
ackQueue = QueuePrefix + ackQueue;

src/ServiceControl.Connector.MassTransit/PoisonQueueLengthCustomCheck.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ public override async Task<CheckResult> PerformCheck(CancellationToken cancellat
3030

3131
return isEmpty
3232
? CheckResult.Pass
33-
: CheckResult.Failed($"Queue `{poisonQueue}` has {length} messages that could not be forwarded to ServiceControl.");
33+
: CheckResult.Failed($"Queue `{poisonQueue}` has {length} messages that could not be forwarded to ServiceControl");
3434
}
3535
}

0 commit comments

Comments
 (0)