12. Given the function
$$
f(x)=\left\{\begin{array}{ll}
\frac{1}{2} x+\frac{3}{2}, & x \leqslant 1 ; \\
\ln x, & x>1
\end{array}\right.
$$
$(\ln x$ is the natural logarithm with base $\mathrm{e}$, $\mathrm{e}=2.71828 \cdots)$. If there exist real numbers $m, n (m<n)$, such that $f(m)=f(n)$, then the range of $n-m$ is ( ).
(A) $\left(0, \mathrm{e}^{2}+3\right)$
(B) $\left(4, \mathrm{e}^{2}-1\right]$
(C) $\left[5-2 \ln 2, e^{2}-1\right]$
(D) $[5-2 \ln 2,4)$
12. C.

It is known that when the slopes are equal, $n-m$ reaches its minimum value, i.e., $(\ln x)' = \frac{1}{2} \Rightarrow x = 2$.
At this point, $f(x) = \ln x$ passes through the point $(2, \ln 2)$.
If $f(x) = \ln 2 = \frac{1}{2} x + \frac{3}{2}$, then $x = 2 \ln 2 - 3$.
At this point, $n-m = 5 - 2 \ln 2$.
Also, when $f(m) = f(n) = 2$, $m = 1, n = e^2$, at this time, $n-m = e^2 - 1$ reaches its maximum value.
Therefore, $n-m \in [5 - 2 \ln 2, e^2 - 1]$.