/// <summary> /// Creates a string representation of arguments of max 200 characters for logging. /// </summary> /// <param name="request">The request whose arguments are to be logged.</param> /// <returns>String representation of first argument only.</returns> internal static string GetArgumentsString(JsonRpcRequest request) { const int maxLength = 128; if (request.ArgumentCount == 0) { return("[]"); } if (request.ArgumentNames is null) { var stringBuilder = new StringBuilder(); stringBuilder.Append('['); for (int i = 0; i < request.ArgumentCount; ++i) { if (request.TryGetArgumentByNameOrIndex(null, i, null, out object?value)) { Format(stringBuilder, value); stringBuilder.Append(", "); } else { stringBuilder.Append("<unformattable>"); } if (stringBuilder.Length > maxLength) { return($"{stringBuilder.ToString(0, maxLength)}...(truncated)"); } } stringBuilder.Length -= 2; // Trim trailing comma stringBuilder.Append(']'); return(stringBuilder.ToString()); } else { var stringBuilder = new StringBuilder(); stringBuilder.Append('{'); foreach (string key in request.ArgumentNames) { if (request.TryGetArgumentByNameOrIndex(key, -1, null, out object?value)) { stringBuilder.Append(key); stringBuilder.Append(": "); Format(stringBuilder, value); stringBuilder.Append(", "); } else { stringBuilder.Append("<unformattable>"); } if (stringBuilder.Length > maxLength) { return($"{stringBuilder.ToString(0, maxLength)}...(truncated)"); } } stringBuilder.Length -= 2; // Trim trailing comma stringBuilder.Append('}'); return(stringBuilder.ToString()); }