We start by examining a source charge $q_s$ and a test charge $q_t$. If we let $\mathbf{r}$ be the vector from the source charge to the test charge then
$$\mathbf{r}=\mathbf{r_t}\mathbin{-}\mathbf{r_s}$$
$r$ is the magnitude of this vector
$$r=|\mathbf{r_t}\mathbin{-}\mathbf{r_s}|$$
and $\mathbf{\hat{r}}$ the unit vector in the direction of $\mathbf{r}$
$$\mathbf{\hat{r}}=\frac{\mathbf{r}}{r}=\frac{\mathbf{r_t}\mathbin{-}\mathbf{r_s}}{|\mathbf{r_t}\mathbin{-}\mathbf{r_s}|}$$
We then write Coulomb’s Law for the electric force vector of the source charge on the test charge as
$$\mathbf{F}=\frac{1}{4\pi\epsilon_0}\frac{q_s q_t}{r^2}\mathbf{\hat{r}}$$
If we have $n$ source charges $q_1$,$q_2$. . . $q_n$ at $\mathbf{r_1}$, $\mathbf{r_2}$. . .$\mathbf{r_n}$ then the total force on the test charge is found by adding the $n$ individual forces.
$$\mathbf{F}=\frac{q_t}{4\pi\epsilon_0}\sum_{i=1}^n\frac{q_i}{r_i^2}\mathbf{\hat{r_i}}$$
Thus for this discrete charge distribution the Electric Field Strength (electric force per unit charge)in the region of the test charge is given by
$$\mathbf{E}(\mathbf{r_t})=\frac{1}{4\pi\epsilon_0}\sum_{i=1}^n\frac{q_1}{r_i^2}\mathbf{\hat{r_i}}$$
For a continuous charge distribution we replace the sum by an integral:
$$\mathbf{E}(\mathbf{r_t})=\frac{1}{4\pi\epsilon_0}\int\frac{dq}{r^2}\mathbf{\hat{r}}$$
There are three types of continuous charge distributions:
(i) Line charges for which
$$dq=\text{charge per unit length times line element}=\lambda(\mathbf{r})dl$$
(ii) Surface charges for which
$$dq=\text{charge per unit area times surface element}=\sigma(\mathbf{r})da$$
(iii) Volume charges for which
$$dq=\text{charge per unit volume times volume element}=\rho(\mathbf{r})dV$$
Note the charge per unit length/area/volume need not be a constant – it can depend on $\mathbf{r}$ that is it may be a scalar function of $x$, $y$ and $z$. We can now proceed to calculate $\mathbf{E}$ for various charge distributions
First we consider a wire of length $L$ laid along the $x$ axis with its endpoints at $x=\mathbin{-}\frac{L}{2}$ and $x=+\frac{L}{2}$ as shown in Fig. 1. The wire has a constant charge per unit length $\lambda$. We are to find the Electric field vector at a point distant $d$ units from the midpoint of the wire in the perpendicular direction. This test point lies on the y axis and has coordinates $(0, d)$. There are an infinite number of source charges all along the wire from one end point to the other with a generic point being $(x, 0)$. We have
$$\mathbf{r_t}=d\mathbf{\hat{k}}$$
$$\mathbf{r_s}=x\mathbf{\hat{i}}$$
thus
$$\mathbf{r}=\mathbf{r_t}\mathbin{-}\mathbf{r_s}=\mathbin{-}x\mathbf{\hat{i}}+d\mathbf{\hat{k}}$$
$$r^2=x^2+d^2$$
$$\mathbf{\hat{r}}=\frac{\mathbf{r}}{r}=\frac{\mathbin{-}x\mathbf{\hat{i}}+d\mathbf{\hat{k}}}{\sqrt{x^2+d^2}}$$
$$dq=\lambda dx$$
Thus
$$\mathbf{E}=\frac{1}{4\pi\epsilon_0}\int\frac{dq}{r^2}\mathbf{\hat{r}}=\frac{1}{4\pi\epsilon_0}\int_{\mathbin{-}\frac{L}{2}}^{+\frac{L}{2}}\frac{\lambda dx}{x^2+d^2}\frac{\mathbin{-}x\mathbf{\hat{i}}+d\mathbf{\hat{k}}}{\sqrt{x^2+d^2}}$$
This is a sum of two integrals but the odd integral involving $\mathbf{\hat{i}}$ is zero over the given range of integration. Only the even integral involving $\mathbf{\hat{k}}$ survives and we can introduce a factor of two and change the lower limit to zero. This gives
$$\mathbf{E}=\frac{2\lambda d\mathbf{\hat{k}}}{4\pi\epsilon_0}\int_0^{\frac{L}{2}}\frac{dx}{(x^2+d^2)^{\frac{3}{2}}}$$
Using the substitution $x=d\tan\theta$ and neglecting the preceding constants, this integral becomes
$$\int_0^{\arctan{\frac{L}{2d}}}\frac{d\sec^2\theta d\theta}{d^3\sec^3\theta}=\frac{1}{d^2}\int_0^{arctan{\frac{L}{2d}}}\cos\theta d\theta=\frac{1}{d^2}\sin\arctan\left(\frac{L}{2d}\right)=\frac{L}{d^2\sqrt{4d^2+L^2}}=\frac{\frac{L}{2}}{d^2\sqrt{d^2+\frac{L^2}{4}}}$$
Hence we finally have
$$\mathbf{E}=\frac{2\lambda d\mathbf{\hat{k}}}{4\pi\epsilon_0}\frac{\frac{L}{2}}{d^2\sqrt{d^2+\frac{L^2}{4}}}=\frac{1}{4\pi\epsilon_0}\frac{\lambda L}{d\sqrt{d^2+\frac{L^2}{4}}}\mathbf{\hat{k}}$$
This is the value of the field at the test point. Note that if $d\gg L$ meaning that if the test point is very far from the line compared to the length of the line, then the formula becomes
$$\mathbf{E}=\frac{1}{4\pi\epsilon_0}\frac{\lambda L}{d^2}\mathbf{\hat{k}}$$
This formula is telling us that from very far away the line begins to look like a point charge $q=\lambda L$
On the other hand if $L\gg d$ meaning the wire is very long compared the distance $d$ in effect an “infinite” wire, then
$$\mathbf{E}=\frac{1}{4\pi\epsilon_0}\frac{2\lambda}{d}\mathbf{\hat{k}}$$
which is the field of an infinite straight wire.
We can use the result for a straight wire from above to find the Electric field at a point $d$ above the center of a square loop of side $L$ carrying $\lambda$ units of charge per unit length. This is shown in Fig. 2. By Pythagoras’ Theorem the distance from the center of one side of the loop to the test point is
$$D=\sqrt{d^2+\frac{L^2}{4}}$$
By our previous result each side of the loop produces an electric field vector $\mathbf{E}$ that is shown in red in Fig. 2. The magnitude of this vector is
$$E=\frac{\lambda L}{4\pi\epsilon_0D\sqrt{D^2+\frac{L^2}{4}}}$$
The vector $\mathbf{E}$ has vertical and horizontal components $\mathbf{E_y}$ and $\mathbf{E_x}$. These components are shown in red in Fig. 2. The vertical components due to the four sides reinforce each other while the horizontal components cancel out so we ignore these.
The vertical component of one side is
$$E\sin\theta=E\times\frac{d}{D}=\frac{\lambda Ld}{4\pi\epsilon_0D^2\sqrt{D^2+\frac{L^2}{4}}}=\frac{\lambda Ld}{4\pi\epsilon_0(d^2+\frac{L^2}{4})\sqrt{d^2+\frac{L^2}{2}}}$$
Where in the last step we substituted for $D$. Each side contributes a vertical component of this magnitude so we can just multiply by four to find the total contribution. Putting in our unit vector $\mathbf{\hat{k}}$ we can now write the final result as
$$\mathbf{E}=\frac{1}{4\pi\epsilon_0}\frac{4\lambda Ld}{(d^2+\frac{L^2}{4})\sqrt{d^2+\frac{L^2}{2}}}\mathbf{\hat{k}}$$
There are two interesting limiting cases. The first one is $d=0$ at the center of the loop. Our formula tells us that here $E=0$. This makes sense because the four vectors, one for each side, are now in the same plane. They point North, South, East and West so to speak and cancel out perfectly givng a resultant total field of zero. The second limiting case occurs if $d\gg L$. Our formula then becomes
$$\mathbf{E}=\frac{1}{4\pi\epsilon_0}\frac{4\lambda L}{d^2}\mathbf{\hat{k}}$$
This just means that from far away our loop looks like a point charge $q=4\lambda L$