Skip to content

Commit 70a67de

Browse files
committed
Simplify RenderPropertyValueUnaligned by delegating to string.Format
1 parent f5aa6e6 commit 70a67de

File tree

1 file changed

+1
-46
lines changed

1 file changed

+1
-46
lines changed

src/Serilog.Sinks.OpenTelemetry/Sinks/OpenTelemetry/Formatting/CleanMessageTemplateFormatter.cs

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -95,57 +95,12 @@ static void RenderPropertyValueUnaligned(LogEventPropertyValue propertyValue, Te
9595

9696
var value = scalar.Value;
9797

98-
if (formatProvider?.GetFormat(typeof(ICustomFormatter)) is ICustomFormatter customFormatter)
99-
{
100-
output.Write(customFormatter.Format(format, value, formatProvider));
101-
return;
102-
}
103-
10498
if (value == null)
10599
{
106100
output.Write("null");
107101
return;
108102
}
109103

110-
if (value is string str)
111-
{
112-
output.Write(str);
113-
return;
114-
}
115-
116-
if (value is ValueType)
117-
{
118-
if (value is int or uint or long or ulong or decimal or byte or sbyte or short or ushort)
119-
{
120-
output.Write(((IFormattable)value).ToString(format, formatProvider));
121-
return;
122-
}
123-
124-
if (value is double d)
125-
{
126-
output.Write(d.ToString(format, formatProvider));
127-
return;
128-
}
129-
130-
if (value is float f)
131-
{
132-
output.Write(f.ToString(format, formatProvider));
133-
return;
134-
}
135-
136-
if (value is bool b)
137-
{
138-
output.Write(b);
139-
return;
140-
}
141-
}
142-
143-
if (value is IFormattable formattable)
144-
{
145-
output.Write(formattable.ToString(format, formatProvider));
146-
return;
147-
}
148-
149-
output.Write(value);
104+
output.Write(string.Format(formatProvider, "{0}", value));
150105
}
151106
}

0 commit comments

Comments
 (0)