serilog-contrib / Serilog.Sinks.Telegram.Alternative

Serilog.Sinks.Telegram.Alternative is a library to save logging information from Serilog to Telegram.
MIT License
36 stars 12 forks source link

Is it possible to format the text? #11

Closed aeri closed 3 years ago

aeri commented 3 years ago

I would like to be able to apply styles as specified in the Telegram style guide (https://core.telegram.org/bots/api#html-style) but I can't get.

I saw something mentioned about it in #8 but I'm not sure if any progress was made on it.

When i log something like:

Serilog.Log.Write(LogEventLevel.Warning, $"<b>bold</b>");

I receive in my chat: &lt;b&gt;bold&lt;/b&gt;

Is it possible to apply formatting in any way with this library?

Thank you.

SeppPenner commented 3 years ago

I can provide a switch that allows to format the messages as you like (something like a bool allowHtmlFormatting = true. In general, the special HTML chars are HTML encoded (as you already figured out) to avoid formatting issues in Telegram.

aeri commented 3 years ago

That would be great, as far as I see HTML is not currently supported, but is it possible to use now other format techniques like Markdown?

SeppPenner commented 3 years ago

I had some serious trouble with Markdown and MarkdownV2 formatting (To make it look good in Telegram). Please don't ask me what exactly was the problem because I don't really remember. I only know that it was really complicated to construct and escape the characters.

So, if you ask me, the boolean flag (Like a 'I know what I'm doing' flag) is the best option for that and doesn't affect the other users if the default is set to false.

SeppPenner commented 3 years ago

With the next version, you can now use the option useCustomHtmlFormatting and set it to true. I have added a test where this is shown --> Check out: https://github.com/serilog-contrib/Serilog.Sinks.Telegram.Alternative/blob/761e2185a7381c1c2ad29de99e06acb8d91110e5/src/Serilog.Sinks.Telegram.Tests/TestSink.cs#L455

aeri commented 3 years ago

Great, thank you very much for the fast support and maintenance of the library :)