What could be wrong with gas fireplace that turns off when I turn it on?
My first guess would be the thermocouple is bad, or going bad.  The thermocouple is a small device that generates electricity from heat, they are used in gas furnaces and such to shut off the gas in case the pilot goes out (so gas doesn't continue to flow and fill the room).

I admit I'm no expert when it comes to gas fire places, but I had an old gas heater that displayed similar issues and it turned out replacing the thermocouple fixed the problem.  Besides they are usually fairly cheap (a couple dollars maybe), so it's a good place to start trouble shooting.