A function is given:
$f(z)=\frac{1}{\sin(z)}$
which has singular points along the real axis at $z=\pi n$ with integer $n$. The residue at $z=\pi n$ is equal to $(-1)^{n}$ as can be computed using an appropriate formula. Thus, the integral $I_n$ of a closed counterclockwise contour around any one of the $z=\pi n$ points should yield $2\pi i (-1)^{n}$ respectively.
Now, for instance we can integrate a closed contour in the following way:
$I_n=\lim_{\epsilon \to 0}(A(\epsilon)+B(\epsilon)+C(\epsilon)+D(\epsilon))$
where
$A(\epsilon)=\int_{-\epsilon}^{\epsilon}\frac{1}{\sin(\pi n +x-i\epsilon)}dx \text{ }\text{ }\text{ }\text{ }\text{ }\text{ }\text{ , }\text{ }\text{ }\text{ }\text{ }\text{ }B(\epsilon)=\int_{-i\epsilon}^{i\epsilon}\frac{1}{\sin(\pi n +y+\epsilon)}dy$
$C(\epsilon)=\int_{\epsilon}^{-\epsilon}\frac{1}{\sin(\pi n +x+i\epsilon)}dx\text{ }\text{ }\text{ }\text{ }\text{ }\text{ }\text{ , }\text{ }\text{ }\text{ }\text{ }\text{ }D(\epsilon)=\int_{i\epsilon}^{-i\epsilon}\frac{1}{\sin(\pi n +y-\epsilon)}dy$
These partial integrals can be done, since we know the primitive:
$F(z)=\ln\left(\sin\left(\frac{z}{2}\right)\right)-\ln\left(\cos\left(\frac{z}{2}\right)\right)\text{ }\text{ }\text{ }\text{ }\text{ }\text{ }\text{ where }\text{ }\text{ }\text{ }\text{ }\text{ }F'(z)=f(z)$
However, after A, B, C and D are integrated out, their sum adds to zero, in contradiction to the expected result of $2\pi i (-1)^{n}$. Apparently, the approach above contains some mistake? What would be a correct approach to obtain the right result but integrating an explicit contour?