You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
logger.LogWarning($"Expiry time {expiryTime.TotalMilliseconds}ms too low, setting to {MinimumExpiryTime.TotalMilliseconds}ms");
This would result in a log entry to be written as Expiry time 5ms too low, setting to 10ms
where the message_template in the background would be Expiry time 5ms too low, setting to 10ms.
This makes it difficult to search or filter on log entries in log aggregators, since the formatted string could potentially be any value.
From the Roslyn Analyser, there is warning "CA2254: Template should be a static expression", explicitly for these type of log entries, to allow for easier searching and filtering in log aggregators.
If the log writing example was to be changed to this
logger.LogWarning("Expiry time {ExpiryTotalMilliseconds}ms too low, setting to {MinimumExpiryTotalMilliseconds}ms", expiryTime.TotalMilliseconds, MinimumExpiryTime.TotalMilliseconds);
the resulting log entry would still be written as Expiry time 5ms too low, setting to 10ms
but the message_template in the background would be Expiry time {ExpiryTotalMilliseconds}ms too low, setting to {MinimumExpiryTotalMilliseconds}ms
which can be used to filter on all occurrences of this log entry, regardless of the values of expiryTime.TotalMilliseconds or MinimumExpiryTime.TotalMilliseconds
Here is the usage of Log message template explained further, with examples of formatting.
One additional suggestion I would like to make, is that the placeholder names be consistently case formatted, so either always upper CamelCase or lower camelCase.
If you can tell me which formatting you would prefer, I could make a PR with all the logging calls converted.
The text was updated successfully, but these errors were encountered:
The logs that are currently written by RedLock.net, are formatted at the time of writing the log entry.
Example from the current code base:
RedLock.net/RedLockNet.SERedis/RedLock.cs
Line 73 in dcfe373
This would result in a log entry to be written as
Expiry time 5ms too low, setting to 10ms
where the
message_template
in the background would beExpiry time 5ms too low, setting to 10ms.
This makes it difficult to search or filter on log entries in log aggregators, since the formatted string could potentially be any value.
From the Roslyn Analyser, there is warning "CA2254: Template should be a static expression", explicitly for these type of log entries, to allow for easier searching and filtering in log aggregators.
If the log writing example was to be changed to this
the resulting log entry would still be written as
Expiry time 5ms too low, setting to 10ms
but the
message_template
in the background would beExpiry time {ExpiryTotalMilliseconds}ms too low, setting to {MinimumExpiryTotalMilliseconds}ms
which can be used to filter on all occurrences of this log entry, regardless of the values of
expiryTime.TotalMilliseconds
orMinimumExpiryTime.TotalMilliseconds
Here is the usage of Log message template explained further, with examples of formatting.
One additional suggestion I would like to make, is that the placeholder names be consistently case formatted, so either always upper CamelCase or lower camelCase.
If you can tell me which formatting you would prefer, I could make a PR with all the logging calls converted.
The text was updated successfully, but these errors were encountered: