Browse Source
Fix truncation length and strengthen fallback test assertion
pull/25267/head
maliming
4 months ago
No known key found for this signature in database
GPG Key ID: A646B9CB645ECEA4
2 changed files with
5 additions and
2 deletions
-
framework/src/Volo.Abp.Core/Microsoft/Extensions/Logging/AbpLoggerExtensions.cs
-
framework/test/Volo.Abp.Core.Tests/Microsoft/Extensions/Logging/AbpLoggerExtensions_Tests.cs
|
|
|
@ -100,6 +100,7 @@ public static class AbpLoggerExtensions |
|
|
|
} |
|
|
|
|
|
|
|
private const int MaxDataValueLength = 4096; |
|
|
|
private const string TruncationSuffix = "...(truncated)"; |
|
|
|
|
|
|
|
private static string FormatDataValue(object? value) |
|
|
|
{ |
|
|
|
@ -119,7 +120,7 @@ public static class AbpLoggerExtensions |
|
|
|
var json = JsonSerializer.Serialize(value); |
|
|
|
if (json.Length > MaxDataValueLength) |
|
|
|
{ |
|
|
|
return json.Substring(0, MaxDataValueLength) + "...(truncated)"; |
|
|
|
return json.Substring(0, MaxDataValueLength - TruncationSuffix.Length) + TruncationSuffix; |
|
|
|
} |
|
|
|
|
|
|
|
return json; |
|
|
|
|
|
|
|
@ -145,7 +145,8 @@ public class AbpLoggerExtensions_Tests |
|
|
|
logger.LogException(exception); |
|
|
|
|
|
|
|
logger.LastLoggedMessage.ShouldNotBeNull(); |
|
|
|
logger.LastLoggedMessage.ShouldContain("BadObject = "); |
|
|
|
logger.LastLoggedMessage.ShouldContain("BadObject = SelfRef:Loop"); |
|
|
|
logger.LastLoggedMessage.ShouldNotContain("\"Name\""); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
@ -172,6 +173,7 @@ public class AbpLoggerExtensions_Tests |
|
|
|
private class SelfReferencingObject |
|
|
|
{ |
|
|
|
public string Name { get; set; } = default!; |
|
|
|
public override string ToString() => $"SelfRef:{Name}"; |
|
|
|
public SelfReferencingObject? Self { get; set; } |
|
|
|
} |
|
|
|
|
|
|
|
|