Trace formulas for Dirac operators with applications to resonances