See the marked duplicate for answers showing how to create your own `TraceListener` that can intercept debug output. In your case, just write the output to a file instead of sending it to a text box. If you need more specific help, please provide a good [mcve] that shows what you've tried, and explain precisely what specifically you're having trouble with.
– Peter DunihoJul 08 '16 at 16:00