5. If $0<x<\frac{\pi}{2}$, then the range of $f(x)=\tan x+\cot x+\frac{1}{\sin x}-\frac{1}{\cos x}$ is ( ).
A. $\mathbf{R}$
B. $(0,+\infty)$
C. $\left(\frac{1}{2},+\infty\right)$
D. $(1,+\infty)$
5. D.

Let $t=\cos x-\sin x=\sqrt{2} \cos \left(x+\frac{\pi}{4}\right), x \in\left(0, \frac{\pi}{2}\right)$, then $t \in(-1,1)$, and $\sin x \cos x= \frac{1-t^{2}}{2}$, so $f(x)=\frac{1+\cos x-\sin x}{\sin x \cos x}=\frac{2}{1-t}$. Since $1-t \in(0,2)$, it follows that $f(x) \in(1,+\infty)$.