Why are flies so attracted to lights? Well, there are many explanations for this behaviour and not one of them is definite, so I guess you could say that we simply don’t know. But one of the most convincing explanations I’ve found is this: they confuse it with the moon.
During night-times insects use the moon as a navigational tool (for day flying insects this is the sun). They use it to fly straight lines in relation to it. But whenever they see a man made and much brighter light, they get confused. They will try to coordinate a straight line in relation to the light bulb. Unfortunately the light bulb is much to close, so they start to circle.
So next time you’re annoyed by a humming noise, consider this: they are probably just as annoyed as you are!