Serilog.Sinks.SpectreConsole icon indicating copy to clipboard operation
Serilog.Sinks.SpectreConsole copied to clipboard

Support Serilog.Expressions (ITextFormatter)

Open rcdailey opened this issue 2 years ago • 3 comments

I'm not able to pass in an ExpressionTemplate from the Serilog.Expressions package. That makes this library unfortunately unusable for my use case.

Like other sinks, this is a matter of supporting ITextFormatter.

rcdailey avatar Jan 05 '23 13:01 rcdailey

I'm trying to replace the normal template with an ExpressionTemplate in my local fork, but this does not seems to be easy. MessageTemplateParser is made for regular template and is unable to recognize regular tokens from expressions. The extracted tokens are not exposed (see here). The easy way I can think of is to manually exclude the expression tokens inside the sink constructor, but this means it only works with a predefined expression template (meaning that every change done to the template will also need changes to the source code). Serilog provides the Sink method which allows to wrap and override the Emit method, but at this point of the process there is less space for customization and I have no idea on what can be done here.

Have you managed to solve the issue?

netcorefan1 avatar May 28 '23 17:05 netcorefan1

No, I am simply not using this library until it is properly supported. I am not really interested in trying to hack a solution, even if it may be possible.

rcdailey avatar May 28 '23 17:05 rcdailey

There is also a C# port of the library, but with the same issue. I'm afraid that this is not going to be supported mostly because Spectre console rendering requires an IRenderable collection and the proper way to support expressions (hope to be wrong) would be a complete rewrite.

What alternative are you using now? I remember that some years ago I searched for something else when I become aware about this issue, but I found nothing that can even compare with Serilog.

netcorefan1 avatar May 28 '23 18:05 netcorefan1