I went to the endodontics to get treatment on a infected root canal. Does it take up to two years for the infection to go away?

RCT infection. If the rct was completed, the infection should be gone within a few weeks at most. However, if you are referring to a radiolucency on the x-ray, it may take up to 3-4 months for complete bone fill. If it's 2 years and still a problem, discuss options such as retreatment, apico or extraction.
No. The infection usually resolves quite quickly, in the order of days to weeks. The bone that was lost due to the abscess can months to years to fill in. That of course assumes the treatment is successful. Followup is very important to ensure all is well.
Periodic checkup. Depending on the extend of the bone destruction, it may take more than two years for the bone to heal. However, there shouldn't be any active infection (pus, soft tissue swelling, etc). As long as you have no symptoms and the follow-up radiographs show improvement then i will just watch it.
No. The acute infection should be gone in a week or two, depending on the amount of bone destroyed by the infection, it might take up to two years for the bone to fill back in and the "lesion" to disappear on the x-ray.
No. The infection associated with the tooth should heal within a few weeks after root canal treatment. However, the "appearance" of the infection on X-ray image may remain unchanged for a long time...sometimes for a couple of years. In fact, the "appearance" of where the infection used to be on an X-ray image may be visible forever. But, the infection itself is gone. Consult your dentist to be sure.