Skip to content

Commit

Permalink
Introduce ScalarValue.Null (#1774)
Browse files Browse the repository at this point in the history
Introduce ScalarValue.Null
  • Loading branch information
sungam3r committed Dec 14, 2022
1 parent 1fcdf10 commit d5cecf3
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Serilog/Capturing/DepthLimiter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ LogEventPropertyValue ILogEventPropertyValueFactory.CreatePropertyValue(object v
if (depth == _maximumDestructuringDepth)
{
SelfLog.WriteLine("Maximum destructuring depth reached.");
return new ScalarValue(null);
return ScalarValue.Null;
}

return null;
Expand Down
2 changes: 1 addition & 1 deletion src/Serilog/Capturing/PropertyValueConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ LogEventPropertyValue CreatePropertyValue(object? value, bool destructureObjects
LogEventPropertyValue CreatePropertyValue(object? value, Destructuring destructuring, int depth)
{
if (value == null)
return new ScalarValue(null);
return ScalarValue.Null;

if (destructuring == Destructuring.Stringify)
{
Expand Down
5 changes: 5 additions & 0 deletions src/Serilog/Events/ScalarValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ namespace Serilog.Events;
/// </summary>
public class ScalarValue : LogEventPropertyValue
{
/// <summary>
/// Scalar value representing <see langword="null"/>.
/// </summary>
public static ScalarValue Null { get; } = new(null);

/// <summary>
/// Construct a <see cref="ScalarValue"/> with the specified
/// value.
Expand Down
2 changes: 2 additions & 0 deletions test/Serilog.ApprovalTests/Serilog.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ namespace Serilog.Events
{
public ScalarValue(object? value) { }
public object? Value { get; }
public static Serilog.Events.ScalarValue Null { get; }
public override bool Equals(object? obj) { }
public override int GetHashCode() { }
public override void Render(System.IO.TextWriter output, string? format = null, System.IFormatProvider? formatProvider = null) { }
Expand All @@ -409,6 +410,7 @@ namespace Serilog.Events
{
public SequenceValue(System.Collections.Generic.IEnumerable<Serilog.Events.LogEventPropertyValue> elements) { }
public System.Collections.Generic.IReadOnlyList<Serilog.Events.LogEventPropertyValue> Elements { get; }
public static Serilog.Events.SequenceValue Empty { get; }
public override void Render(System.IO.TextWriter output, string? format = null, System.IFormatProvider? formatProvider = null) { }
}
public class StructureValue : Serilog.Events.LogEventPropertyValue
Expand Down

0 comments on commit d5cecf3

Please sign in to comment.