One way to get rid of drain flies is to clean them out and eliminate their breeding grounds. You can do this by using a baking soda, salt and vinegar solution, which you should leave overnight. The next day, pour boiling water into the drain to kill any remaining larvae. Alternatively, you can place a bowl of sugar, vinegar, and water on your counter, surrounded by plastic wrap. This is effective at getting rid of drain flies because the flies are attracted to the sweet temptation. Using an insect spray is also a good idea. Use 5 to 8 seconds per 1000 cubic feet and spray for at least 15 minutes.
The larvae of drain flies are tiny, and it is easy to miss them. However, it is possible to detect adult drain flies with a simple trap. To locate breeding areas, you can invert a clear plastic cup with a thin layer of petroleum jelly or oil. You can also place a transparent piece of tape over the drain to make it easier to see the breeding sites.
Drain flies lay their eggs in biofilm on drain surfaces. In order to breed, they need moist soil. This can come from dirty garbage cans, dirty recycling bins, or even stagnant water in a mop bucket.