Closed vas7n closed 2 years ago
Hi, what would the reason be to disable this behavior? Log message templates are used specifically for the purpose of enabling structured logging. Are you aware of other providers that support disabling structured logs?
Hi! The reason is simple. My administrators forbid creating any other parameters (tags).
Forbidding additional fields seems like an odd decision since this is one of the main reasons for using a tool like Graylog. You can use string interpolation to bypass the structured logging but in general you shouldn't do this because you lose information, and can't easily query your logs.
_logger.LogInformation($"Order {orderId} took {orderTime} seconds");
_logger.LogInformation($"Order {orderId} took {orderTime} seconds");
In this case, I will get a warning: "CA2254: The template must be a static expression"
I fully trust your expert opinion. And if you really think this is a bad idea, you can close the Issue.
Sorry for the delay getting back to you, the warning is there because you are losing the structured data, but that is what you are trying to achieve, so you can ignore it (more info here).
You can disable the warning, or try to convince your admins of the value of structured logs :)
It would be nice to add an option to enable/disable Structured/Semantic Logging.
For example, so that the parameters are not created if I use
_logger.LogInformation("Order {order_id} took {order_time} seconds to process", orderId, orderTime);
.