If you use the complex integration, it is convenient to consider the integrand $\displaystyle f(z)=\ln z\,\frac{e^{-z}-e^{iz}}z$ and closed contour
$$r\to R\to iR \,(\text{along the arch of a big radius R, counter-clockwise})$$
$$\to ir\to r\,(\text{along the arch of a small radius r, clockwise})$$
and the cut along the positive part of the axis X (to make $\ln z $ a single-valued function). We stay on the upper bank of the cut.
Denoting the integral along the arches as $I_{C_R}$ and $I_{C_r}$,
$$\oint f(z)dz=\int_r^R\ln x\,\frac{e^{-x}-e^{ix}}xdx+I_{C_R}+\int_{iR}^{ir}\ln x\,\frac{e^{-x}-e^{ix}}xdx+I_{C_r}=0$$
because we do not have poles inside the contour.
Using $\,\displaystyle x=e^\frac{\pi i}2t\,$ for the second integral,
$$\int_r^R\ln x\,\frac{e^{-x}-e^{ix}}xdx+\int_r^R\ln x\,\frac{e^{-x}-e^{-ix}}xdx=2\int_r^R\ln x\,\frac{e^{-x}-\cos x}xdx$$
$$=\frac{\pi i}2\int_r^R\frac{e^{-ix}-e^{-x}}xdx-I_{C_R}-I_{C_r}$$
Integral along small and big arches tend to zero.
Indeed,
$$I_{C_r}=\int_0^{\pi/2}\ln(re^{i\phi})\frac{e^{-re^{i\phi}}-e^{ire^{i\phi}}}{re^{i\phi}}ire^{i\phi}d\phi=O(r\ln r)\to0 \,\text{at}\,r\to0$$
$$I_{C_R}=\int_0^{\pi/2}\ln(Re^{i\phi})\frac{e^{-Re^{i\phi}}-e^{iRe^{i\phi}}}{Re^{i\phi}}iRe^{i\phi}d\phi=i\int_0^{\pi/2}\ln(Re^{i\phi})\left(e^{-Re^{i\phi}}-e^{iRe^{i\phi}}\right)d\phi$$
where every integral can be estimated by means of Jordan's lemma. For example,
$$\Big|I_1\Big|=\Big|i\int_0^{\pi/2}\ln(Re^{i\phi})e^{-Re^{i\phi}}d\phi\Big|<\ln R\int_0^{\pi/2}e^{-R\cos\phi}d\phi=\ln R\int_0^{\pi/2}e^{-R\sin\phi}d\phi$$
Using $\sin\phi\geqslant \frac2\pi\phi$ for $\phi\in[0;\frac\pi2]$
$$\Big|I_1\Big|<\ln R\int_0^{\pi/2}e^{-\frac2\pi R\phi}d\phi=\frac\pi2\frac{\ln R}R\left(1-e^{-R}\right)\to 0\,\text{at}\,R\to\infty$$
Therefore, leading $r\to 0;\,R\to\infty$
$$2\int_0^\infty\ln x\,\frac{e^{-x}-\cos x}xdx=\frac{\pi i}2\int_0^\infty\frac{e^{-ix}-e^{-x}}xdx$$
$$=\frac\pi2\int_0^\infty\frac{\sin x}xdx+\frac{\pi i}2\int_0^\infty\frac{\cos x-e^{-x}}xdx$$
$$=\frac{\pi^2}4+\frac{\pi i}2\int_0^\infty\frac{\cos x-e^{-x}}xdx$$
The second integral is zero - the approach is exactly the same as for the initial integral (by means of a quarter-circle in the complex plane). But, in fact, we do not need to evaluate it: the initial integral is real, and the last integral is imaginary, so it must equals zero.
Hence,
$$\int_0^\infty\ln x\,\frac{e^{-x}-\cos x}xdx=\frac{\pi^2}8$$