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

Combine output template with log4j/log4net formatter #179

Open
adaskos-signal opened this issue Nov 9, 2023 · 5 comments
Open

Combine output template with log4j/log4net formatter #179

adaskos-signal opened this issue Nov 9, 2023 · 5 comments

Comments

@adaskos-signal
Copy link

Problem

There doesn't seem to be a way to combine log4j/log4net formatters with a template.
The Udp extension that accepts a template uses MessageTemplateTextFormatter directly and doesn't produce an XML message.

Feature request

It would be helpful if we extended both log4j/log4net formatters to accept a template and use it to enhance the log4j:message according to it.

Proposed solution

We can add an optional outputTemplate in both Log4jTextFormatter and Log4netTextFormatter constructors, and then use Serilog's MessageTemplateTextFormatter internally to produce the message attribute, while keeping the rest as is

Copy link
Contributor

github-actions bot commented Nov 9, 2023

Hi there and welcome to this repository!

A maintainer will be with you shortly, but first and foremost I would like to thank you for taking the time to report this issue. Quality is of the highest priority for us, and we would never release anything with known defects. We aim to do our best but unfortunately you are here because you encountered something we didn't expect. Lets see if we can figure out what went wrong and provide a remedy for it.

@FantasticFiasco
Copy link
Owner

Thanks for the suggestion and sorry for the late reply.

@FantasticFiasco
Copy link
Owner

I've seen message templates used for non-structured log events, e.g. Serilog.Sinks.Console, but I haven't seen them used yet for structured log events. If you find a sink that features this combination, preferably by the author of Serilog, please let me know and I'll take a look at it.

@FantasticFiasco FantasticFiasco removed their assignment Jan 15, 2024
@adaskos-signal
Copy link
Author

Hi there. I'm certainly not an expert. I've used about 5 sinks so far in my projects.
I believe you're right, a structured message shouldn't require a message template.
But how does one go with extending the message with extra info, if he so wants?
log2console is not so feature rich and controlling the message helps. Even in seq one might want to extend the logged, without the need to expand to see the parameters.
If you see no value in it, it's ok. I thought it might be an easy extension for whoever wants something similar.

@FantasticFiasco
Copy link
Owner

I think the option we currently have is to take inspiration from one of the existing text formatters (found here), and adapt it to your needs. Please let me know if you encounter any problems with the adaptation.

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