The Formation of MgI 4571 Å in the solar atmosphere