|
|
|
@ -45,8 +45,8 @@ namespace Squidex.Infrastructure.Log |
|
|
|
[Fact] |
|
|
|
public void Should_log_multiple_lines() |
|
|
|
{ |
|
|
|
Log.Log(SemanticLogLevel.Error, w => w.WriteProperty("logMessage", "Msg1")); |
|
|
|
Log.Log(SemanticLogLevel.Error, w => w.WriteProperty("logMessage", "Msg2")); |
|
|
|
Log.Log<None>(SemanticLogLevel.Error, null, (_, w) => w.WriteProperty("logMessage", "Msg1")); |
|
|
|
Log.Log<None>(SemanticLogLevel.Error, null, (_, w) => w.WriteProperty("logMessage", "Msg2")); |
|
|
|
|
|
|
|
var expected1 = |
|
|
|
LogTest(w => w |
|
|
|
@ -129,6 +129,19 @@ namespace Squidex.Infrastructure.Log |
|
|
|
Assert.Equal(expected, output); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_log_with_trace_and_context() |
|
|
|
{ |
|
|
|
Log.LogTrace(1500, (ctx, w) => w.WriteProperty("logValue", ctx)); |
|
|
|
|
|
|
|
var expected = |
|
|
|
LogTest(w => w |
|
|
|
.WriteProperty("logLevel", "Trace") |
|
|
|
.WriteProperty("logValue", 1500)); |
|
|
|
|
|
|
|
Assert.Equal(expected, output); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_log_with_debug() |
|
|
|
{ |
|
|
|
@ -142,6 +155,19 @@ namespace Squidex.Infrastructure.Log |
|
|
|
Assert.Equal(expected, output); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_log_with_debug_and_context() |
|
|
|
{ |
|
|
|
Log.LogDebug(1500, (ctx, w) => w.WriteProperty("logValue", ctx)); |
|
|
|
|
|
|
|
var expected = |
|
|
|
LogTest(w => w |
|
|
|
.WriteProperty("logLevel", "Debug") |
|
|
|
.WriteProperty("logValue", 1500)); |
|
|
|
|
|
|
|
Assert.Equal(expected, output); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_log_with_information() |
|
|
|
{ |
|
|
|
@ -155,6 +181,19 @@ namespace Squidex.Infrastructure.Log |
|
|
|
Assert.Equal(expected, output); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_log_with_information_and_context() |
|
|
|
{ |
|
|
|
Log.LogInformation(1500, (ctx, w) => w.WriteProperty("logValue", ctx)); |
|
|
|
|
|
|
|
var expected = |
|
|
|
LogTest(w => w |
|
|
|
.WriteProperty("logLevel", "Information") |
|
|
|
.WriteProperty("logValue", 1500)); |
|
|
|
|
|
|
|
Assert.Equal(expected, output); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_log_with_warning() |
|
|
|
{ |
|
|
|
@ -168,6 +207,19 @@ namespace Squidex.Infrastructure.Log |
|
|
|
Assert.Equal(expected, output); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_log_with_warning_and_context() |
|
|
|
{ |
|
|
|
Log.LogWarning(1500, (ctx, w) => w.WriteProperty("logValue", ctx)); |
|
|
|
|
|
|
|
var expected = |
|
|
|
LogTest(w => w |
|
|
|
.WriteProperty("logLevel", "Warning") |
|
|
|
.WriteProperty("logValue", 1500)); |
|
|
|
|
|
|
|
Assert.Equal(expected, output); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_log_with_warning_exception() |
|
|
|
{ |
|
|
|
@ -183,6 +235,22 @@ namespace Squidex.Infrastructure.Log |
|
|
|
Assert.Equal(expected, output); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_log_with_warning_exception_and_context() |
|
|
|
{ |
|
|
|
var exception = new InvalidOperationException(); |
|
|
|
|
|
|
|
Log.LogWarning(exception, 1500, (ctx, w) => w.WriteProperty("logValue", ctx)); |
|
|
|
|
|
|
|
var expected = |
|
|
|
LogTest(w => w |
|
|
|
.WriteProperty("logLevel", "Warning") |
|
|
|
.WriteProperty("logValue", 1500) |
|
|
|
.WriteException(exception)); |
|
|
|
|
|
|
|
Assert.Equal(expected, output); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_log_with_error() |
|
|
|
{ |
|
|
|
@ -196,6 +264,19 @@ namespace Squidex.Infrastructure.Log |
|
|
|
Assert.Equal(expected, output); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_log_with_error_and_context() |
|
|
|
{ |
|
|
|
Log.LogError(1500, (ctx, w) => w.WriteProperty("logValue", ctx)); |
|
|
|
|
|
|
|
var expected = |
|
|
|
LogTest(w => w |
|
|
|
.WriteProperty("logLevel", "Error") |
|
|
|
.WriteProperty("logValue", 1500)); |
|
|
|
|
|
|
|
Assert.Equal(expected, output); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_log_with_error_exception() |
|
|
|
{ |
|
|
|
@ -211,6 +292,22 @@ namespace Squidex.Infrastructure.Log |
|
|
|
Assert.Equal(expected, output); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_log_with_error_exception_and_context() |
|
|
|
{ |
|
|
|
var exception = new InvalidOperationException(); |
|
|
|
|
|
|
|
Log.LogError(exception, 1500, (ctx, w) => w.WriteProperty("logValue", ctx)); |
|
|
|
|
|
|
|
var expected = |
|
|
|
LogTest(w => w |
|
|
|
.WriteProperty("logLevel", "Error") |
|
|
|
.WriteProperty("logValue", 1500) |
|
|
|
.WriteException(exception)); |
|
|
|
|
|
|
|
Assert.Equal(expected, output); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_log_with_fatal() |
|
|
|
{ |
|
|
|
@ -224,6 +321,19 @@ namespace Squidex.Infrastructure.Log |
|
|
|
Assert.Equal(expected, output); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_log_with_fatal_and_context() |
|
|
|
{ |
|
|
|
Log.LogFatal(1500, (ctx, w) => w.WriteProperty("logValue", ctx)); |
|
|
|
|
|
|
|
var expected = |
|
|
|
LogTest(w => w |
|
|
|
.WriteProperty("logLevel", "Fatal") |
|
|
|
.WriteProperty("logValue", 1500)); |
|
|
|
|
|
|
|
Assert.Equal(expected, output); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_log_with_fatal_exception() |
|
|
|
{ |
|
|
|
@ -239,6 +349,22 @@ namespace Squidex.Infrastructure.Log |
|
|
|
Assert.Equal(expected, output); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_log_with_fatal_exception_and_context() |
|
|
|
{ |
|
|
|
var exception = new InvalidOperationException(); |
|
|
|
|
|
|
|
Log.LogFatal(exception, 1500, (ctx, w) => w.WriteProperty("logValue", ctx)); |
|
|
|
|
|
|
|
var expected = |
|
|
|
LogTest(w => w |
|
|
|
.WriteProperty("logLevel", "Fatal") |
|
|
|
.WriteProperty("logValue", 1500) |
|
|
|
.WriteException(exception)); |
|
|
|
|
|
|
|
Assert.Equal(expected, output); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_log_nothing_when_exception_is_null() |
|
|
|
{ |
|
|
|
@ -265,6 +391,20 @@ namespace Squidex.Infrastructure.Log |
|
|
|
Assert.StartsWith(expected.Substring(0, 55), output, StringComparison.Ordinal); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_measure_trace_with_contex() |
|
|
|
{ |
|
|
|
Log.MeasureTrace("My Message", (ctx, w) => w.WriteProperty("message", ctx)).Dispose(); |
|
|
|
|
|
|
|
var expected = |
|
|
|
LogTest(w => w |
|
|
|
.WriteProperty("logLevel", "Trace") |
|
|
|
.WriteProperty("message", "My Message") |
|
|
|
.WriteProperty("elapsedMs", 0)); |
|
|
|
|
|
|
|
Assert.StartsWith(expected.Substring(0, 55), output, StringComparison.Ordinal); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_measure_debug() |
|
|
|
{ |
|
|
|
@ -279,6 +419,20 @@ namespace Squidex.Infrastructure.Log |
|
|
|
Assert.StartsWith(expected.Substring(0, 55), output, StringComparison.Ordinal); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_measure_debug_with_contex() |
|
|
|
{ |
|
|
|
Log.MeasureDebug("My Message", (ctx, w) => w.WriteProperty("message", ctx)).Dispose(); |
|
|
|
|
|
|
|
var expected = |
|
|
|
LogTest(w => w |
|
|
|
.WriteProperty("logLevel", "Debug") |
|
|
|
.WriteProperty("message", "My Message") |
|
|
|
.WriteProperty("elapsedMs", 0)); |
|
|
|
|
|
|
|
Assert.StartsWith(expected.Substring(0, 55), output, StringComparison.Ordinal); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_measure_information() |
|
|
|
{ |
|
|
|
@ -293,6 +447,20 @@ namespace Squidex.Infrastructure.Log |
|
|
|
Assert.StartsWith(expected.Substring(0, 55), output, StringComparison.Ordinal); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_measure_information_with_contex() |
|
|
|
{ |
|
|
|
Log.MeasureInformation("My Message", (ctx, w) => w.WriteProperty("message", ctx)).Dispose(); |
|
|
|
|
|
|
|
var expected = |
|
|
|
LogTest(w => w |
|
|
|
.WriteProperty("logLevel", "Information") |
|
|
|
.WriteProperty("message", "My Message") |
|
|
|
.WriteProperty("elapsedMs", 0)); |
|
|
|
|
|
|
|
Assert.StartsWith(expected.Substring(0, 55), output, StringComparison.Ordinal); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_log_with_extensions_logger() |
|
|
|
{ |
|
|
|
@ -334,7 +502,7 @@ namespace Squidex.Infrastructure.Log |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
sut.Log(SemanticLogLevel.Debug, w => w.WriteProperty("should", "throw")); |
|
|
|
sut.Log<None>(SemanticLogLevel.Debug, null, (_, w) => w.WriteProperty("should", "throw")); |
|
|
|
|
|
|
|
Assert.False(true); |
|
|
|
} |
|
|
|
|