FantasticFiasco / serilog-sinks-udp

A Serilog sink sending UDP packages over the network.
Apache License 2.0
30 stars 15 forks source link

Combine output template with log4j/log4net formatter #179

Open adaskos-signal opened 11 months ago

adaskos-signal commented 11 months ago

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

github-actions[bot] commented 11 months ago

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 commented 9 months ago

Thanks for the suggestion and sorry for the late reply.

FantasticFiasco commented 9 months ago

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.

adaskos-signal commented 8 months ago

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 commented 8 months ago

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.