Browse Source

Fix truncation length and strengthen fallback test assertion

pull/25267/head
maliming 6 months ago
parent
commit
aa3c7723f0
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 3
      framework/src/Volo.Abp.Core/Microsoft/Extensions/Logging/AbpLoggerExtensions.cs
  2. 4
      framework/test/Volo.Abp.Core.Tests/Microsoft/Extensions/Logging/AbpLoggerExtensions_Tests.cs

3
framework/src/Volo.Abp.Core/Microsoft/Extensions/Logging/AbpLoggerExtensions.cs

@ -100,6 +100,7 @@ public static class AbpLoggerExtensions
} }
private const int MaxDataValueLength = 4096; private const int MaxDataValueLength = 4096;
private const string TruncationSuffix = "...(truncated)";
private static string FormatDataValue(object? value) private static string FormatDataValue(object? value)
{ {
@ -119,7 +120,7 @@ public static class AbpLoggerExtensions
var json = JsonSerializer.Serialize(value); var json = JsonSerializer.Serialize(value);
if (json.Length > MaxDataValueLength) if (json.Length > MaxDataValueLength)
{ {
return json.Substring(0, MaxDataValueLength) + "...(truncated)"; return json.Substring(0, MaxDataValueLength - TruncationSuffix.Length) + TruncationSuffix;
} }
return json; return json;

4
framework/test/Volo.Abp.Core.Tests/Microsoft/Extensions/Logging/AbpLoggerExtensions_Tests.cs

@ -145,7 +145,8 @@ public class AbpLoggerExtensions_Tests
logger.LogException(exception); logger.LogException(exception);
logger.LastLoggedMessage.ShouldNotBeNull(); logger.LastLoggedMessage.ShouldNotBeNull();
logger.LastLoggedMessage.ShouldContain("BadObject = "); logger.LastLoggedMessage.ShouldContain("BadObject = SelfRef:Loop");
logger.LastLoggedMessage.ShouldNotContain("\"Name\"");
} }
[Fact] [Fact]
@ -172,6 +173,7 @@ public class AbpLoggerExtensions_Tests
private class SelfReferencingObject private class SelfReferencingObject
{ {
public string Name { get; set; } = default!; public string Name { get; set; } = default!;
public override string ToString() => $"SelfRef:{Name}";
public SelfReferencingObject? Self { get; set; } public SelfReferencingObject? Self { get; set; }
} }

Loading…
Cancel
Save