23 public static string LogFormat(
this IResult result, uint level = 0)
25 ArgumentNullException.ThrowIfNull(result);
30 var stringBuilder =
new StringBuilder();
31 if (result.Error !=
null)
33 stringBuilder.Append(result.Error.Message);
34 if (result.Error is RestResultError<RestError> restError)
36 stringBuilder.Append(
" (");
37 if (restError.Error !=
null)
39 stringBuilder.Append(restError.Error.Code);
40 stringBuilder.Append(
": ");
41 stringBuilder.Append(restError.Error.Message);
42 stringBuilder.Append(
'|');
45 stringBuilder.Append(restError.Message);
46 if ((restError.Error?.Errors.HasValue ??
false) && restError.Error.Errors.Value.Count > 0)
48 stringBuilder.Append(
" (");
49 foreach (var error
in restError.Error.Errors.Value)
51 stringBuilder.Append(error.Key);
52 stringBuilder.Append(
':');
59 stringBuilder.Append(
',');
62 stringBuilder.Remove(stringBuilder.Length - 1, 1);
65 stringBuilder.Append(
')');
69 if (result.Inner !=
null)
71 stringBuilder.Append(Environment.NewLine);
73 for (var i = 0; i < level; ++i)
74 stringBuilder.Append(
'\t');
75 stringBuilder.Append(result.Inner.LogFormat(level));
78 return stringBuilder.ToString();
86 static void FormatErrorDetails(IPropertyErrorDetails propertyErrorDetails, StringBuilder stringBuilder)
88 if (propertyErrorDetails ==
null)
93 if (propertyErrorDetails.Errors !=
null && propertyErrorDetails.MemberErrors !=
null)
95 stringBuilder.Append(
',');
98 if (propertyErrorDetails.MemberErrors !=
null)
100 stringBuilder.Append(
'{');
101 foreach (var error
in propertyErrorDetails.MemberErrors)
103 stringBuilder.Append(error.Key);
104 stringBuilder.Append(
':');
106 stringBuilder.Append(
',');
109 stringBuilder.Remove(stringBuilder.Length - 1, 1);
110 stringBuilder.Append(
'}');
119 static void FormatErrorDetails(IEnumerable<IErrorDetails>? errorDetails, StringBuilder stringBuilder)
121 if (errorDetails ==
null)
124 stringBuilder.Append(
'[');
125 foreach (var error
in errorDetails)
127 stringBuilder.Append(error.Code);
128 stringBuilder.Append(
':');
129 stringBuilder.Append(error.Message);
130 stringBuilder.Append(
',');
133 stringBuilder.Remove(stringBuilder.Length - 1, 1);
134 stringBuilder.Append(
']');