Concept:
Whenever expressions involving \( xe^x \) appear in integrals, substitution with
\[
t=xe^x
\]
is generally very effective because:
\[
\frac{d}{dx}(xe^x)=e^x(x+1).
\]
Step 1: Preparing the integrand for substitution.
Given,
\[
I=\int \frac{x+1}{x(1+xe^x)^2}\,dx.
\]
Multiply numerator and denominator by \( e^x \):
\[
I=\int \frac{(x+1)e^x}{xe^x(1+xe^x)^2}\,dx.
\]
Now let
\[
t=xe^x.
\]
Then,
\[
dt=e^x(x+1)\,dx.
\]
Hence,
\[
I=\int \frac{dt}{t(1+t)^2}.
\]
Step 2: Using partial fractions.
Resolve:
\[
\frac{1}{t(1+t)^2}
=
\frac{A}{t}
+\frac{B}{1+t}
+\frac{C}{(1+t)^2}.
\]
Multiplying throughout by \( t(1+t)^2 \):
\[
1=A(1+t)^2+Bt(1+t)+Ct.
\]
Expanding:
\[
1=A(1+2t+t^2)+Bt+Bt^2+Ct.
\]
Grouping like terms:
\[
1=A+(2A+B+C)t+(A+B)t^2.
\]
Comparing coefficients:
\[
A=1,
\]
\[
A+B=0,
\]
\[
2A+B+C=0.
\]
Substituting \( A=1 \):
\[
1+B=0
\Rightarrow B=-1.
\]
Again,
\[
2(1)-1+C=0
\Rightarrow 1+C=0
\Rightarrow C=-1.
\]
Therefore,
\[
\frac{1}{t(1+t)^2}
=
\frac1t-\frac1{1+t}-\frac1{(1+t)^2}.
\]
Step 3: Integrating term by term.
Thus,
\[
I=
\int\left(
\frac1t-\frac1{1+t}-\frac1{(1+t)^2}
\right)dt.
\]
Integrating:
\[
I=\ln|t|-\ln|1+t|+\frac1{1+t}+C.
\]
Step 4: Substituting back \( t=xe^x \).
Hence,
\[
I=
\ln\left|
\frac{xe^x}{1+xe^x}
\right|
+
\frac1{1+xe^x}
+C.
\]
Therefore,
\[
\boxed{
\ln\left|
\frac{xe^x}{1+xe^x}
\right|
+
\frac1{1+xe^x}
+C
}.
\]