mattwcole / gelf-extensions-logging

GELF provider for Microsoft.Extensions.Logging
MIT License
109 stars 42 forks source link

Option to enable/disable Semantic Logging #66

Closed vas7n closed 2 years ago

vas7n commented 2 years ago

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

image

mattwcole commented 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?

vas7n commented 2 years ago

Hi! The reason is simple. My administrators forbid creating any other parameters (tags).

mattwcole commented 2 years ago

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");
vas7n commented 2 years ago
_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.

mattwcole commented 2 years ago

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 :)