Skip to content

Commit bea3a62

Browse files
committed
Final tweak - only use literal formatting at the top level when opted-in.
1 parent 46674e6 commit bea3a62

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedValueFormatter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ protected StyleReset ApplyStyle(TextWriter output, ConsoleThemeStyle style, ref
3434
return _theme.Apply(output, style, ref invisibleCharacterCount);
3535
}
3636

37-
public int Format(LogEventPropertyValue value, TextWriter output, string format)
37+
public int Format(LogEventPropertyValue value, TextWriter output, string format, bool literalTopLevel = false)
3838
{
39-
return Visit(new ThemedValueFormatterState { Output = output, Format = format, IsTopLevel = true }, value);
39+
return Visit(new ThemedValueFormatterState { Output = output, Format = format, IsTopLevel = literalTopLevel }, value);
4040
}
4141

4242
public abstract ThemedValueFormatter SwitchTheme(ConsoleTheme theme);

src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/ThemedMessageTemplateRenderer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,15 @@ int RenderAlignedPropertyTokenUnbuffered(PropertyToken pt, TextWriter output, Lo
126126

127127
int RenderValue(ConsoleTheme theme, ThemedValueFormatter valueFormatter, LogEventPropertyValue propertyValue, TextWriter output, string format)
128128
{
129-
if (_isLiteral && propertyValue is ScalarValue sv && (sv.Value is string str || sv.Value is char ch))
129+
if (_isLiteral && propertyValue is ScalarValue sv && sv.Value is string)
130130
{
131131
var count = 0;
132132
using (theme.Apply(output, ConsoleThemeStyle.String, ref count))
133133
output.Write(sv.Value);
134134
return count;
135135
}
136136

137-
return valueFormatter.Format(propertyValue, output, format);
137+
return valueFormatter.Format(propertyValue, output, format, _isLiteral);
138138
}
139139
}
140140
}

0 commit comments

Comments
 (0)