The 2.5 motor from about 1995 - 2002 or so is notorious for blowing head gaskets. Unfortunately I don't believe the Forester was ever available with any other motor until the 3rd gen, when I think some of the turbo foresters got the turbo 2.0 from the WRX.The CEL was always on for various reasons, it required a $1,000 head gasket job, and the oil wouldn't stay out of the coolant, and vice versa. Even after the head gasket job. There was always something wrong with it.
AFAIK most head gasket issues on the 2.5 were cured by ~2003 or so.
As far as longevity goes, Subaru 1.8, 2.0 and 2.2 motors have a pretty good reputation for lasting a long time. If you can stay away from the 2.5 you're in good shape.
I had a 99 OBW with the trouble-prone 2.5 and I was lucky. No problems in 80k miles of ownership. But I could see the writing on the wall so I got rid of it in 2007.