8.319. $\frac{1+\sin 2 x+\cos 2 x}{1+\sin 2 x-\cos 2 x}+\sin x\left(1+\operatorname{tg} x \operatorname{tg} \frac{x}{2}\right)=4$.
Solution.

Domain of definition: $\left\{\begin{array}{l}\cos x \neq 0, \\ \cos \frac{x}{2} \neq 0, \\ 1+\sin 2 x-\cos 2 x \neq 0 .\end{array}\right.$

From the condition we have

$\frac{\sin ^{2} x+\cos ^{2} x+2 \sin x \cos x+\cos ^{2} x-\sin ^{2} x}{\sin ^{2} x+\cos ^{2} x+2 \sin x \cos x-\cos ^{2} x+\sin ^{2} x}+\sin x\left(1+\frac{\sin x \sin \frac{x}{2}}{\cos x \cos \frac{x}{2}}\right)-4=0 \Leftrightarrow$

$\Leftrightarrow \frac{2 \sin x \cos x+2 \cos ^{2} x}{2 \sin x \cos x+2 \sin ^{2} x}+\frac{\sin x\left(\cos x \cos \frac{x}{2}+\sin x \sin \frac{x}{2}\right)}{\cos x \cos \frac{x}{2}}-4=0 \Leftrightarrow$

$\Leftrightarrow \frac{2 \cos x(\sin x+\cos x)}{2 \sin x(\cos x+\sin x)}+\frac{\sin x \cos \frac{x}{2}}{\cos x \cos \frac{x}{2}}-4=0, \frac{\cos x}{\sin x}+\frac{\sin x}{\cos x}=4$,

$\frac{\cos ^{2} x+\sin ^{2} x}{2 \sin x \cos x}=2, \frac{1}{\sin 2 x}=2, \sin 2 x=\frac{1}{2}, 2 x=(-1)^{k} \frac{\pi}{6}+\pi k$,

$x=(-1)^{k} \frac{\pi}{12}+\frac{\pi k}{2}, k \in Z$

Answer: $x=(-1)^{k} \frac{\pi}{12}+\frac{\pi k}{2}, k \in Z$