An estimator for the dynamical temperature in an arbitrary ensemble is derived in the framework of Bayesian statistical mechanics and the maximum entropy principle. We test this estimator numerically by a simulation of the two-dimensional XY-model in the canonical ensemble. As this model is critical in the whole region of temperatures below the Berezinski-Kosterlitz-Thouless critical temperature TBKT , we use a generalization of Wolff's uni-cluster algorithm. The numerical results allow us to confirm the robustness of the analytical expression for the microscopic estimator of the temperature. This microscopic estimator has also the advantage that it gives a direct measure of the thermalization process and can be used to compute absolute errors associated to statistical fluctuations. In consequence, this estimator allows for a direct, absolute and astringent test of the ergodicity of the underlying Markov process, which encodes the algorithm used in a numerical simulation.