The M A P sensor could be your problem, it is in the inlet manifold or one of the air inlet hoses or pipes. Iam not sure where it is on a legacy but it has given me grief over the years on all different models of cars, same symptoms. the veins get blocked and the engine compensates by over fueling or under fueling which will cause a dirty idle or misfire when revved, sometimes. Might be worth a try, it can be cleaned easily enough with petrol and paint brush, could be a dead plug aswell. You said you fitted a new boost gauge, make sure its air tight at the connection.