Thermodynamics on the apparent horizon in generalized gravity theories