Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for logging structured data #40

Merged
merged 8 commits into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 39 additions & 39 deletions src/ZeroLog.Tests/LogEventTests.Append.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void Teardown()
public void should_append_string()
{
_logEvent.Append("abc");
_logEvent.WriteToStringBuffer(_output);
_logEvent.WriteToStringBuffer(_output, null);

Assert.AreEqual("abc", _output.ToString());
}
Expand All @@ -48,7 +48,7 @@ public void should_append_string()
public void should_append_null_string()
{
_logEvent.Append((string)null);
_logEvent.WriteToStringBuffer(_output);
_logEvent.WriteToStringBuffer(_output, null);

Assert.AreEqual("null", _output.ToString());
}
Expand All @@ -58,7 +58,7 @@ public void should_append_byte_array()
{
var bytes = Encoding.Default.GetBytes("abc");
_logEvent.AppendAsciiString(bytes, bytes.Length);
_logEvent.WriteToStringBuffer(_output);
_logEvent.WriteToStringBuffer(_output, null);

Assert.AreEqual("abc", _output.ToString());
}
Expand All @@ -68,7 +68,7 @@ public void should_append_byte_span()
{
var bytes = Encoding.Default.GetBytes("abc");
_logEvent.AppendAsciiString(bytes.AsSpan());
_logEvent.WriteToStringBuffer(_output);
_logEvent.WriteToStringBuffer(_output, null);

Assert.AreEqual("abc", _output.ToString());
}
Expand All @@ -77,7 +77,7 @@ public void should_append_byte_span()
public void should_append_char_span()
{
_logEvent.AppendAsciiString("abc".AsSpan());
_logEvent.WriteToStringBuffer(_output);
_logEvent.WriteToStringBuffer(_output, null);

Assert.AreEqual("abc", _output.ToString());
}
Expand All @@ -87,7 +87,7 @@ public void should_ignore_byte_array_with_negative_length()
{
var bytes = Encoding.Default.GetBytes("abc");
_logEvent.AppendAsciiString(bytes, -1);
_logEvent.WriteToStringBuffer(_output);
_logEvent.WriteToStringBuffer(_output, null);

Assert.AreEqual("", _output.ToString());
}
Expand All @@ -96,7 +96,7 @@ public void should_ignore_byte_array_with_negative_length()
public void should_ignore_empty_byte_array()
{
_logEvent.AppendAsciiString(new byte[0], 0);
_logEvent.WriteToStringBuffer(_output);
_logEvent.WriteToStringBuffer(_output, null);

Assert.AreEqual("", _output.ToString());
}
Expand All @@ -105,7 +105,7 @@ public void should_ignore_empty_byte_array()
public void should_ignore_empty_byte_span()
{
_logEvent.AppendAsciiString(ReadOnlySpan<byte>.Empty);
_logEvent.WriteToStringBuffer(_output);
_logEvent.WriteToStringBuffer(_output, null);

Assert.AreEqual("", _output.ToString());
}
Expand All @@ -114,7 +114,7 @@ public void should_ignore_empty_byte_span()
public void should_ignore_empty_char_span()
{
_logEvent.AppendAsciiString(ReadOnlySpan<char>.Empty);
_logEvent.WriteToStringBuffer(_output);
_logEvent.WriteToStringBuffer(_output, null);

Assert.AreEqual("", _output.ToString());
}
Expand All @@ -128,7 +128,7 @@ public void should_truncate_byte_array_after_too_many_args()

var bytes = Encoding.Default.GetBytes("abc");
_logEvent.AppendAsciiString(bytes, bytes.Length);
_logEvent.WriteToStringBuffer(_output);
_logEvent.WriteToStringBuffer(_output, null);

Assert.AreEqual(new string('.', _argCapacity) + LogManager.Config.TruncatedMessageSuffix, _output.ToString());
}
Expand All @@ -142,7 +142,7 @@ public void should_truncate_byte_span_after_too_many_args()

var bytes = Encoding.Default.GetBytes("abc");
_logEvent.AppendAsciiString(bytes.AsSpan());
_logEvent.WriteToStringBuffer(_output);
_logEvent.WriteToStringBuffer(_output, null);

Assert.AreEqual(new string('.', _argCapacity) + LogManager.Config.TruncatedMessageSuffix, _output.ToString());
}
Expand All @@ -155,7 +155,7 @@ public void should_truncate_char_span_after_too_many_args()
_logEvent.Append(".");

_logEvent.AppendAsciiString("abc".AsSpan());
_logEvent.WriteToStringBuffer(_output);
_logEvent.WriteToStringBuffer(_output, null);

Assert.AreEqual(new string('.', _argCapacity) + LogManager.Config.TruncatedMessageSuffix, _output.ToString());
}
Expand All @@ -164,7 +164,7 @@ public void should_truncate_char_span_after_too_many_args()
public void should_append_null_byte_array()
{
_logEvent.AppendAsciiString((byte[])null, 0);
_logEvent.WriteToStringBuffer(_output);
_logEvent.WriteToStringBuffer(_output, null);

Assert.AreEqual("null", _output.ToString());
}
Expand All @@ -178,7 +178,7 @@ public void should_append_unsafe_byte_array()
_logEvent.AppendAsciiString(b, bytes.Length);
}

_logEvent.WriteToStringBuffer(_output);
_logEvent.WriteToStringBuffer(_output, null);

Assert.AreEqual("abc", _output.ToString());
}
Expand All @@ -197,7 +197,7 @@ public void should_truncate_unsafe_byte_array_after_too_many_args()
_logEvent.AppendAsciiString(b, bytes.Length);
}

_logEvent.WriteToStringBuffer(_output);
_logEvent.WriteToStringBuffer(_output, null);

Assert.AreEqual(new string('.', _argCapacity) + LogManager.Config.TruncatedMessageSuffix, _output.ToString());
}
Expand All @@ -206,7 +206,7 @@ public void should_truncate_unsafe_byte_array_after_too_many_args()
public void should_append_null_unsafe_byte_array()
{
_logEvent.AppendAsciiString((byte*)null, 0);
_logEvent.WriteToStringBuffer(_output);
_logEvent.WriteToStringBuffer(_output, null);

Assert.AreEqual("null", _output.ToString());
}
Expand All @@ -215,7 +215,7 @@ public void should_append_null_unsafe_byte_array()
public void should_append_true()
{
_logEvent.Append(true);
_logEvent.WriteToStringBuffer(_output);
_logEvent.WriteToStringBuffer(_output, null);

Assert.AreEqual("True", _output.ToString());
}
Expand All @@ -224,7 +224,7 @@ public void should_append_true()
public void should_append_false()
{
_logEvent.Append(false);
_logEvent.WriteToStringBuffer(_output);
_logEvent.WriteToStringBuffer(_output, null);

Assert.AreEqual("False", _output.ToString());
}
Expand All @@ -233,7 +233,7 @@ public void should_append_false()
public void should_append_byte()
{
_logEvent.Append((byte)255);
_logEvent.WriteToStringBuffer(_output);
_logEvent.WriteToStringBuffer(_output, null);

Assert.AreEqual("255", _output.ToString());
}
Expand All @@ -242,7 +242,7 @@ public void should_append_byte()
public void should_append_char()
{
_logEvent.Append('€');
_logEvent.WriteToStringBuffer(_output);
_logEvent.WriteToStringBuffer(_output, null);

Assert.AreEqual("€", _output.ToString());
}
Expand All @@ -251,7 +251,7 @@ public void should_append_char()
public void should_append_short()
{
_logEvent.Append((short)4321);
_logEvent.WriteToStringBuffer(_output);
_logEvent.WriteToStringBuffer(_output, null);

Assert.AreEqual("4321", _output.ToString());
}
Expand All @@ -260,7 +260,7 @@ public void should_append_short()
public void should_append_int()
{
_logEvent.Append(1234567890);
_logEvent.WriteToStringBuffer(_output);
_logEvent.WriteToStringBuffer(_output, null);

Assert.AreEqual("1234567890", _output.ToString());
}
Expand All @@ -269,7 +269,7 @@ public void should_append_int()
public void should_append_long()
{
_logEvent.Append(1234567890123456789L);
_logEvent.WriteToStringBuffer(_output);
_logEvent.WriteToStringBuffer(_output, null);

Assert.AreEqual("1234567890123456789", _output.ToString());
}
Expand All @@ -278,7 +278,7 @@ public void should_append_long()
public void should_append_float()
{
_logEvent.Append(0.123f);
_logEvent.WriteToStringBuffer(_output);
_logEvent.WriteToStringBuffer(_output, null);

Assert.AreEqual("0.123", _output.ToString());
}
Expand All @@ -287,7 +287,7 @@ public void should_append_float()
public void should_append_double()
{
_logEvent.Append(0.123d);
_logEvent.WriteToStringBuffer(_output);
_logEvent.WriteToStringBuffer(_output, null);

Assert.AreEqual("0.123", _output.ToString());
}
Expand All @@ -296,7 +296,7 @@ public void should_append_double()
public void should_append_decimal()
{
_logEvent.Append(792281625142643.37593543950335m);
_logEvent.WriteToStringBuffer(_output);
_logEvent.WriteToStringBuffer(_output, null);

Assert.AreEqual("792281625142643.37593543950335", _output.ToString());
}
Expand All @@ -305,7 +305,7 @@ public void should_append_decimal()
public void should_append_guid()
{
_logEvent.Append(new Guid("129ac124-e588-47e5-9d3d-fa3a4d174e29"));
_logEvent.WriteToStringBuffer(_output);
_logEvent.WriteToStringBuffer(_output, null);

Assert.AreEqual("129ac124-e588-47e5-9d3d-fa3a4d174e29", _output.ToString());
}
Expand All @@ -314,7 +314,7 @@ public void should_append_guid()
public void should_append_date_time()
{
_logEvent.Append(new DateTime(2017, 01, 12, 13, 14, 15));
_logEvent.WriteToStringBuffer(_output);
_logEvent.WriteToStringBuffer(_output, null);

Assert.AreEqual("2017-01-12 13:14:15.000", _output.ToString());
}
Expand All @@ -323,7 +323,7 @@ public void should_append_date_time()
public void should_append_time_span()
{
_logEvent.Append(new TimeSpan(1, 2, 3, 4, 5));
_logEvent.WriteToStringBuffer(_output);
_logEvent.WriteToStringBuffer(_output, null);

Assert.AreEqual("1.02:03:04.0050000", _output.ToString());
}
Expand All @@ -346,7 +346,7 @@ public void should_append_all_types()
_logEvent.Append(new DateTime(2017, 01, 12, 13, 14, 15));
_logEvent.Append(new TimeSpan(1, 2, 3, 4, 5));

_logEvent.WriteToStringBuffer(_output);
_logEvent.WriteToStringBuffer(_output, null);

Assert.AreEqual("AbCFalseTrue128£12345-128999999999999999999123.456789.012345.67890129ac124-e588-47e5-9d3d-fa3a4d174e292017-01-12 13:14:15.0001.02:03:04.0050000", _output.ToString());
}
Expand All @@ -373,7 +373,7 @@ public void should_append_format()
_logEvent.Append(new TimeSpan(1, 2, 3, 4, 5));
_logEvent.AppendUnmanaged(new UnmanagedStruct() { A = 1, B = 2, C = 3 });

_logEvent.WriteToStringBuffer(_output);
_logEvent.WriteToStringBuffer(_output, null);

Assert.AreEqual("AbCFalseTrue128£12345-128999999999999999999123.456789.012345.67890129ac124-e588-47e5-9d3d-fa3a4d174e292017-01-12 13:14:15.0001.02:03:04.00500001-2-3", _output.ToString());
}
Expand All @@ -390,7 +390,7 @@ public void should_append_format_multiple_times()
_logEvent.Append(10);
_logEvent.Append("foo");

_logEvent.WriteToStringBuffer(_output);
_logEvent.WriteToStringBuffer(_output, null);

Assert.AreEqual("foo(bar42)[baz10]foo", _output.ToString());
}
Expand All @@ -407,7 +407,7 @@ public void should_append_unmanaged_from_append_generic()
C = 3
});

_logEvent.WriteToStringBuffer(_output);
_logEvent.WriteToStringBuffer(_output, null);

Assert.AreEqual("1-2-3", _output.ToString());
}
Expand Down Expand Up @@ -435,31 +435,31 @@ private void should_append_nullable<T>()
where T : struct
{
((dynamic)_logEvent).Append((T?)null);
_logEvent.WriteToStringBuffer(_output);
_logEvent.WriteToStringBuffer(_output, null);

Assert.AreEqual("null", _output.ToString());

_output.Clear();
_logEvent.Initialize(Level.Info, null, LogEventArgumentExhaustionStrategy.Default);

((dynamic)_logEvent).AppendGeneric((T?)null);
_logEvent.WriteToStringBuffer(_output);
_logEvent.WriteToStringBuffer(_output, null);

Assert.AreEqual("null", _output.ToString());

_output.Clear();
_logEvent.Initialize(Level.Info, null, LogEventArgumentExhaustionStrategy.Default);

((dynamic)_logEvent).Append((T?)new T());
_logEvent.WriteToStringBuffer(_output);
_logEvent.WriteToStringBuffer(_output, null);

Assert.AreNotEqual("null", _output.ToString());

_output.Clear();
_logEvent.Initialize(Level.Info, null, LogEventArgumentExhaustionStrategy.Default);

((dynamic)_logEvent).AppendGeneric((T?)new T());
_logEvent.WriteToStringBuffer(_output);
_logEvent.WriteToStringBuffer(_output, null);

Assert.AreNotEqual("null", _output.ToString());
}
Expand All @@ -473,7 +473,7 @@ public void should_truncate_log_message()
_logEvent.Append(".");

_logEvent.Append("!");
_logEvent.WriteToStringBuffer(_output);
_logEvent.WriteToStringBuffer(_output, null);

Assert.AreEqual(new string('.', _argCapacity) + LogManager.Config.TruncatedMessageSuffix, _output.ToString());
}
Expand All @@ -487,7 +487,7 @@ public void should_not_truncate_log_message()
_logEvent.Append(".");

_logEvent.Append("!");
_logEvent.WriteToStringBuffer(_output);
_logEvent.WriteToStringBuffer(_output, null);

Assert.AreEqual(new string('.', _argCapacity * 2) + "!", _output.ToString());
}
Expand Down
Loading