Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blacklist for LoggerParameters (Placeholders) #697

Closed
FreeYourMinds opened this issue Feb 15, 2024 · 4 comments · Fixed by #698
Closed

Blacklist for LoggerParameters (Placeholders) #697

FreeYourMinds opened this issue Feb 15, 2024 · 4 comments · Fixed by #698

Comments

@FreeYourMinds
Copy link

Story

While using ECS Logging the placeholder {Message} was used within the structured logging resulting in the ECS formater replacing the whole message with only the content of the parameter in the ECS log. Therefore it would be good if there was a possibility to declare certain placeholders as black listed.

Example of the problem

logger.LogError(ex, "The operation for object {ObjectId} in state {State} failed with error: {Message}", "TestObject", "deleted", ex.Message);

Expected ECS log message

"The operation for object TestObject in state deleted failed with error: InvalidOperation: Can not update deleted Items"

Actuals ECS log message

"InvalidOperation: Can not update deleted Items"

Feature request

Add a way to configure a blacklist for parameter names to avoid accidentally overwriting reserved fields in ECS logs

@meziantou
Copy link
Owner

There is no blacklist. However, you can configure MA0139 to a dummy type.

Message;MyNamespace.InvalidLoggerType
namespace MyNamespace;

[Obsolete("Do not use")]
internal sealed class InvalidLoggerType { private InvalidLoggerType() { } }

@FreeYourMinds
Copy link
Author

Thank you for providing an example to solve this with the current implementation.

I am aware that there currently is no blacklist. I also already considered (mis)using the type configuration to solve my situation, but concluded that an explicit implementation would be preferable, which resulted in the feature request.

Therefore it still would be great if you could consider adding a blacklist to make the intention explicit

@meziantou
Copy link
Owner

I think a solution would be to allow the configuration syntax

# No type specified to add a parameter name to the deny list
ParameterName;

Also, the diagnostic message should be clearer in this case.

Would it solve your issue?

@FreeYourMinds
Copy link
Author

Yes, this does solve my issue well.

Thank you for implementing it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants