Yes.
z=xy-y+lnx+2 so
dz= (y+ 1/x)dx + (x-1)dy
And that is an "exact" differential precisely because it is the differential of z.
Now suppose you were given the differential form (y+ 1/x)dx+ (x- 1)dy without having been given z. How would you determine whether it was an exact differential?
If
(y+ 1/x)= \frac{\partial z}{\partial x}
for some function z and
x-1= \frac{\partial z}{\partial y}
then
\frac{\partial(y+ 1/x)}{\partial y}= \frac{\partial^2 z}{\partial x\partial y}
and
\frac{\partial(x-1)}{\partial x}= \frac{\partial^2 z}{\partial y\partial x}
and so must be equal. Fortunately, it is easy to see that each second derivative is 1 and so they are in fact equal.
Okay, now, how would we find z? Knowing that
x-1= \frac{\partial z}{\partial y}
integrating with respect to y (treating x as a constant) we get z= xy- y+ C, except that, since we are treating x as a constant, that "constant of integration", C, may depend on x: z= xy- y+ C(x). Differentiating that with respect to x,
\frac{\partial z}{\partial x}= y+ C'(x)= y+ 1/x
Notice that the "y" terms cancel (it was the "cross condition" above that guarenteed that) and so we have C'(x)= 1/x. Then C(x)= ln(x)+ C where "C" now really is a constant.
Any z(x,y)= xy- y+ ln(x)+ C satisfies dz= (y+ 1/x)dx+ (x-1)dy.