why $\int \frac{1}{1+\sin(x)+\cos(x)}dx = \ln\left | \tan(\frac{x}{2})+1 \right |+const.$? This is how I solve $$\int \frac{1}{1+\sin(x)+\cos(x)}dx$$, but I got the wrong answer, and the correct answer is $$\ln\left | \tan(\frac{x}{2})+1 \right |+\text{const}.$$
How to solve this？


\begin{align}
\sin x &= \frac{2\tan(x/2)}{1 + \tan(x/2)} \\
\cos x &= \frac{1-\tan^2x}{1+ \tan^2x} \\
1+\sin x+\cos x &= \frac{2 + 2\tan(x/2)}{1+\tan(x/2)} \\
I &= \int\frac{dx}{1+\sin x+\cos x} \\
&= \int\frac{\sec(x/2)}{2+\tan(x/2)} dx
\end{align}
Let $z=\tan(x/2)$, then $dz=\frac12\sec(x/2)dx$ and
\begin{align}
I &= \int \frac22 \frac{dz}{1+z} \\
&= \log|z+1| +c \\
&= \log(\tan(x/2)+1) + c
\end{align}
