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

Remove a property after message render #335

Open
StrangeW opened this issue Jun 27, 2023 · 2 comments
Open

Remove a property after message render #335

StrangeW opened this issue Jun 27, 2023 · 2 comments

Comments

@StrangeW
Copy link

StrangeW commented Jun 27, 2023

Hello

Is your feature request related to a problem? Please describe.
I'm not sure if this is a Feature, but I'll need to be able to remove a property from the logs once the message is build.

Describe the solution you'd like
In idea, when I run

_logger.LogInformation("I run {ControlerName} at {RunDate}", nameof(HomeController), DateTime.Now);

I would like the message to be I run HomeController at 06/27/2023 17:45:23 but the RunDate property not to be present

{
	"@timestamp": "2023-06-27T17:45:23.0784393+02:00",
	"level": "Information",
	"messageTemplate": "I run {ControlerName} at {RunDate}",
	"message": "I run HomeController at 06/27/2023 17:45:23",
	"fields": {
		"ControlerName": "HomeController",
		"SourceContext": "MyApp.WebApp.Controllers.HomeController",
		"RequestPath": "/",
		"Environment": "DEV",
		"MachineName": "Test",
		"ApplicationName": "MyApp"
	}
}

Additional context
I send my logs to applications like ElasticSearch or AppInsight and each property is indexed. I'd like to do away with these fields.

@StrangeW
Copy link
Author

I've already looked at ILogEventEnricher, where I can delete the property, but the message is interpreted afterwards. I get a message like "I run HomeController at {RunDate}" instead of "I run {ControlerName} at {RunDate}".

@nblumhardt
Copy link
Member

Hi @StrangeW! A wrapper sink could achieve this (construct a new log event with new message template and selected properties, before forwarding to wrapped sink). LoggerSinkConfiguration.Wrap() is the starting point to check out. HTH!

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

No branches or pull requests

2 participants