Rainbow is form when total internal reflection occur in water droplet.
Fog is formed by moisture in which water droplet are of very smaller size. To form rainbow there must be some minimum size of water droplet , which exist in water droplet of rain and not in fog. Therefore rainbow form during rain and not in fog.