The partition function is strongly related to a very useful tool in probability theory called the moment generating function(al) of the probability distribution.
For any probability distribution $p$ of some random variable $X$, the generating function $\mathcal{M}(z)$ is defined as being:
\begin{equation}
\mathcal{M}(z) \equiv \left\langle e^{zX}\right\rangle
\end{equation}
so that we have for instance:
\begin{equation}
\left(\frac{\partial \mathcal{M}}{\partial z}\right)_{z = 0} = \langle X \rangle,
\end{equation}
\begin{equation}
\left(\frac{\partial^2 \mathcal{M}}{\partial z^2}\right)_{z = 0} = \langle X^2 \rangle,
\end{equation}
and in general
\begin{equation}
\mathcal{M}^{(n)}(0) = \langle X^n \rangle
\end{equation}
Now, in statistical mechanics the canonical ensembles (with the exception of the microcanonical ensemble) have an exponential form with respect to their corresponding fluctuating thermodynamic random variables (the energy $E$ for the canonical ensemble, the energy $E$ and the number of particles $N$ for the grand canonical ensemble and the energy $E$ and the volume $V$ for the isobaric ensemble, to name a few) so that the probability distribution itself has a form like this
\begin{equation}
p_t(X) = f(X)e^{tX}
\end{equation}where $t$ is a real number corresponding to one of the intensive thermodynamic variables.
The moment generating function for probabilities like these will look like
\begin{equation}
\mathcal{M}(z) =\left \langle e^{zX}\right\rangle = \int \mathrm d\mu(x) \:f(x) e^{tx} e^{zx}
\end{equation}
It is quite easy to realize that if we define a partition function as being
\begin{equation}
Z(t) \equiv \int \mathrm d\mu(x) \: f(x)e^{tx},
\end{equation} we find that
\begin{equation}
\mathcal{M}(z) = Z(t+z)
\end{equation}so that
\begin{equation}
\mathcal{M}^{(n)}(0) = Z^{(n)}(t)
\end{equation}
In general in statistical mechanics, we prefer looking at the log of the partition function (which is also incidentally the logarithm of the moment generating function) as it allows to generate the cumulants of the distribution instead of the moments by applying successive derivatives.