Skip to content

Commit c13562e

Browse files
committed
Refactor JSON formatting and rendering internals
Removed obsolete parameters from StructureValue and ValueFormatterState constructors to align with updated Serilog API.
1 parent b192fb0 commit c13562e

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

Serilog.Sinks.RichTextBox.WinForms.Colored.Test/Integration/JsonFormattingTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public void PrettyPrintJson_EmptyCollectionsFormatCorrectly()
185185
{
186186
var emptyArray = new LogEventProperty("EmptyArray", new SequenceValue(Array.Empty<LogEventPropertyValue>()));
187187
var emptyDict = new LogEventProperty("EmptyDict", new DictionaryValue(new Dictionary<ScalarValue, LogEventPropertyValue>()));
188-
var emptyObject = new LogEventProperty("EmptyObject", new StructureValue(Array.Empty<LogEventProperty>(), null));
188+
var emptyObject = new LogEventProperty("EmptyObject", new StructureValue(Array.Empty<LogEventProperty>()));
189189
var logEvent = new LogEvent(DateTimeOffset.Now, LogEventLevel.Information, null, _parser.Parse("Array: {EmptyArray:j}, Dict: {EmptyDict:j}, Object: {EmptyObject:j}"), new[] { emptyArray, emptyDict, emptyObject });
190190

191191
var options = new RichTextBoxSinkOptions(

Serilog.Sinks.RichTextBox.WinForms.Colored/Sinks/RichTextBoxForms/Formatting/JsonValueFormatter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace Serilog.Sinks.RichTextBoxForms.Formatting
2929
{
3030
public class JsonValueFormatter : ValueFormatter
3131
{
32-
private readonly StringBuilder _literalBuilder = new(64);
32+
private readonly StringBuilder _literalBuilder = new();
3333
private readonly StringBuilder _scalarBuilder = new();
3434
private readonly StringBuilder _jsonStringBuilder = new();
3535

@@ -39,7 +39,7 @@ public JsonValueFormatter(RichTextBoxSinkOptions options) : base(options)
3939

4040
protected override ValueFormatterState CreateInitialState(IRtfCanvas canvas, string format, bool isLiteral)
4141
{
42-
return new ValueFormatterState(canvas, format, isLiteral, 0, Options.SpacesPerIndent, true);
42+
return new ValueFormatterState(canvas, format, isLiteral, 0, Options.SpacesPerIndent);
4343
}
4444

4545
protected override bool VisitScalarValue(ValueFormatterState state, ScalarValue scalar)

Serilog.Sinks.RichTextBox.WinForms.Colored/Sinks/RichTextBoxForms/Rendering/EventPropertyTokenRenderer.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class EventPropertyTokenRenderer : ITokenRenderer
3030
{
3131
private readonly RichTextBoxSinkOptions _options;
3232
private readonly PropertyToken _token;
33+
private readonly StringBuilder _stringBuilder = new();
3334

3435
public EventPropertyTokenRenderer(PropertyToken token, RichTextBoxSinkOptions options)
3536
{
@@ -51,14 +52,14 @@ public void Render(LogEvent logEvent, IRtfCanvas canvas)
5152
}
5253
else
5354
{
54-
var sb = new StringBuilder();
55+
_stringBuilder.Clear();
5556

56-
using (var writer = new StringWriter(sb))
57+
using (var writer = new StringWriter(_stringBuilder))
5758
{
5859
propertyValue.Render(writer, _token.Format, _options.FormatProvider);
5960
}
6061

61-
_options.Theme.Render(canvas, StyleToken.SecondaryText, sb.ToString());
62+
_options.Theme.Render(canvas, StyleToken.SecondaryText, _stringBuilder.ToString());
6263
}
6364
}
6465
}

0 commit comments

Comments
 (0)