Primary encephalitis happens when a virus, bacterium, fungus, or parasite directly infects the brain. The infection may be located in only one area. It may also be located in many areas and spread throughout the brain.