Maintaining healthy trees is the best way to prevent borer attack. Stressed trees, for whatever reason, draw borers to them as well as other opportunistic species. Regular watering and fertilization will go a long way towards giving trees the resources to cope with insect attack. Injury of trees from 'mower blight' and string trimmers makes dogwoods and many other trees susceptible to attack. The first sign that you may have borers is holes in the bark with exuded sawdust (frass) typically on the main trunk and larger branches. Numerous methods can be tried to limit the damage. It may be possible to kill some borers by carefully guiding a fine piece of wire into the opening and puncturing the larva. Other insecticidal products, while not specifically registered and/or labeled for this use, will often control borers if they are not too far inside the tree. These insecticides are available in pressurized cans that are equipped with with a slender pliable plastic nozzle that can be carefully guided into the tunnel similar to the wire mentioned above. Also, homeowners report considerable success using properly registered products for this and other borers by using syringes and fairly long hypodermic needles. Finally, some success has been reported using systemic insecticides (imidacloprid) as a basal drench early in spring both as preventative and curative.
Of course, the best way to deal with the dogwood borer is to never permit it to attack in the first place. Adult dogwood borers lay their eggs between about the last week of May through mid-June (in zones 6 & 7). Apply a preventive spray to trunks and branches to control adults and hatching larvae. Avoid pruning or damaging the trunk except during the dormant season - wound sites on trunks and branches are injuries and will attract the moths. Contact your local Extension office for other insecticide recommendations.