The partition function of QFT is defined as
$$Z=\int\mathcal{D}\varphi e^{iS[\varphi]}.$$
Now, it is a general fact that this formal path integral can be computed perturbatively as (sketchy)
$$Z=\sum_{\Gamma}\frac{\lambda^{V}}{\mathrm{sym}(\Gamma)}\mathcal{A}_{\Gamma}.$$
where the sum is over all Feynman amplitudes of closed (=vacuum) Feynman graphs and where $\lambda$ denotes the coupling. This equality is obtained by perturbing around the coupling $\lambda$ and computing Gaussian integrals, i.e.
$$Z=\int\mathcal{D}\varphi e^{iS[\varphi]}=\int\mathcal{D}\varphi e^{iS_{\mathrm{kin}}[\varphi]}\bigg (\sum_{k}\frac{1}{k!}\bigg[i\int\,\mathrm{d}^{4}x\mathcal{L}_{\mathrm{int}}\bigg ]^{k}\bigg )=\\\sum_{k}\int\,\mathrm{d}^{4}z_{1}\dots\mathrm{d}^{4}z_{k}\bigg [\text{apply propagator pairwise to fields }\mathcal{L}_{\mathrm{int}}(\varphi(z_{k}))\dots\mathcal{L}_{\mathrm{int}}(\varphi(z_{1}))\bigg ]=\sum_{\Gamma}\frac{\lambda^{V}}{\mathrm{sym}(\Gamma)}\mathcal{A}_{\Gamma}.$$
Now, in many text i have seen the claim that the last equality is only true for the free energy, i.e. the claim that
$$F=-i\cdot\mathrm{ln}(Z)=\sum_{\Gamma}\frac{\lambda^{V}}{\mathrm{sym}(\Gamma)}\mathcal{A}_{\Gamma}.$$
I am confused, which formula is correct? The formula for $Z$ or for $F$?