The insect involved is the Yellow-horned Horntail. The yellow "horns" of the first part of the common name are actually the antennae and the horntail from the second part of the name, is a growth at the back end of the insect. This appendage is not, as we first assumed, the ovipositor. That organ is under the wasp. I have been unable to find any description of what the horn at the back end is used for...it may simply be designed to be impressive and ward off those that might attack this wasp.
This species of horntail (Urocerus flavicornis) lays eggs in dead or dying trees. This they accomplish by inserting thier ovipositor into the tree some 20 mm. They lay a small number of eggs, pump in a solution containing a wood decaying fungus and then move on to the next oviposition site. The larvae hatch out of the eggs in 3-4 weeks, burrowing into the rotting wood and feeding on the fungi digested wood for a number of years. Just before the larvae pupates, it burrows back to near the surface of the wood. After pupation, the adult wasp uses its jaws to chew a hole our of the tree to exit.
If the log has been milled into lumber the larvae are capable of surviving in a structure build from the wood and will emerge even if they have to chew through wallboard or hardwood flooring. There is even a record of the European equivalent chewing through lead sheathing covering a timber!