I have a 6 foot piece of 8 x 8 hardwood barn beam that I'm intending to use as a mantel.The beam weighs about 130 lbs. My plan is to mount it on four half inch x 10 inch long lag bolts, each screwed five inches into a stud, with the remaining five inches going into the back of the beam. Is this safe, and/or is there a better way to do it?
Assuming the math checks out (ie, you have 2x6 studs), this should work. If you only have 2x4s, I'd think about getting more lags into the equation.
If it was my project, I'd use longer lags to have more resistance to rotation in the mantel. (12" lags give about 6" in the mantel, though you'd lose a little in the drywall and the removal of the lag's head.)
There's two hard things to this plan: the first is making sure you hit the absolute center of the studs. I'd cut drywall away to make sure I'm centered. (It'll be behind the wood, so any patching can be pretty basic.) Second is getting your lags drilled absolutely perfectly dead perpendicular, both to the mantel and the wall. The best case is using a drill press for the mantel, though that might be tough. Using a spotter and a speed square can be very helpful. Obviously, your holes need to line up perfectly as well.
To prevent the mantel from slipping off in the future, all you'd really need is a couple of long toe screws through the mantle into the studs. They aren't doing much work, so that doesn't need to be overdone.
If all this sounds daunting, you might explore other options, like a french cleat (metal, not wood) that would be more forgiving in terms of install complexity.
If the surface of the wall is unfinished, or to be covered with stone / brick after the mantel is installed, there are two good options.
I'm personally a fan of the french cleat as @isherwood mentioned. Here is a link to a video of a guy doing just that. It does come with the drawback that the mantel will be away form the wall based on the thickness of the cleat. Pic from the linked video:
The other approach is to use a backer board. Basically, you mount the mantel to a sheet of plywood or material that is slightly larger (taller and longer) than the size of the mantel using screws or lags. Then you mount that to the wall, putting screws / lags into the overlapping pieces above / below or at the ends. This could be mounted on top of the wall if it is to be finished and covered. Or if the wall needs to be flush, you can cut away your wall surface the same size as the backer board.
I found an example of this, here's a pic:
I am sure you solved this by now, but wanted to add some good references for others down the road. I'm about to install one as well.