-
Notifications
You must be signed in to change notification settings - Fork 23
Description
Serilog's console sink, for example, which is obviously the most commonly used sink, calls the user-provided IFormatProvider
's GetFormat
method with an ICustomFormatter
type as it forwards the formatting to Serilog's built-in ScalarValue.Render
, which looks for an ICustomFormatter
— see this.
This effectively enables custom formatting of parameters of any type. This is also the behavior of the standard string.Format
method — see the official .NET docs.
This library's OpenTelemetrySinkOptions.FormatProvider
, however, works differently. It merely passes the custom IFormatProvider
as the second argument for parameters of types that implement IFormattable.ToString
; which typically expect IFormatProvider.GetFormat
to return a specialized subset of types that they recognize (DateTime.ToString
, for instance, only expects a DateTimeFormatInfo
object).
What this means, in effect, is that with this sink you currently can't truly customize the formatting of log parameters embedded into log messages, like you can with the console sink and whatnot.
Consider changing the behavior to be consistent with the console and file sinks, as well as enabling the scenario mentioned above.
This bug was also reported and subsequently fixed for the file sink — see this issue.