Skip to content

Commit 63f0a95

Browse files
authored
Apply string literal formatting in display mode (#25)
1 parent 4a95053 commit 63f0a95

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

Build.ps1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ foreach ($src in ls src/*) {
2424
echo "build: Packaging project in $src"
2525

2626
& dotnet build -c Release --version-suffix=$buildSuffix
27-
& dotnet pack -c Release --include-symbols -o ..\..\artifacts --version-suffix=$suffix --no-build
27+
if ($suffix) {
28+
& dotnet pack -c Release --include-source -o ..\..\artifacts --version-suffix=$suffix --no-build
29+
} else {
30+
& dotnet pack -c Release --include-source -o ..\..\artifacts --no-build
31+
}
2832
if($LASTEXITCODE -ne 0) { exit 1 }
2933

3034
Pop-Location
@@ -41,4 +45,4 @@ foreach ($test in ls test/*.Tests) {
4145
Pop-Location
4246
}
4347

44-
Pop-Location
48+
Pop-Location

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,12 @@ public int FormatLiteralValue(ScalarValue scalar, TextWriter output, string form
159159
if (value is string str)
160160
{
161161
using (ApplyStyle(output, ConsoleThemeStyle.String, ref count))
162-
JsonValueFormatter.WriteQuotedJsonString(str, output);
162+
{
163+
if (format != "l")
164+
JsonValueFormatter.WriteQuotedJsonString(str, output);
165+
else
166+
output.Write(str);
167+
}
163168
return count;
164169
}
165170

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System.IO;
2+
using Serilog.Events;
3+
using Serilog.Sinks.SystemConsole.Formatting;
4+
using Serilog.Sinks.SystemConsole.Themes;
5+
using Xunit;
6+
7+
namespace Serilog.Sinks.Console.Tests.Formatting
8+
{
9+
public class ThemedDisplayValueFormatterTests
10+
{
11+
[Theory]
12+
[InlineData("Hello", null, "\"Hello\"")]
13+
[InlineData("Hello", "l", "Hello")]
14+
public void StringFormattingIsApplied(string s, string format, string expected)
15+
{
16+
var f = new ThemedDisplayValueFormatter(ConsoleTheme.None, null);
17+
var sw = new StringWriter();
18+
f.FormatLiteralValue(new ScalarValue(s), sw, format);
19+
var actual = sw.ToString();
20+
Assert.Equal(expected, actual);
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)