- Home /
Question by
msloan · Aug 18, 2012 at 02:32 AM ·
tracesystem.diagnostics
How do I add a TraceListener so that it listens to Trace.WriteLine?
Given this code:
using UnityEngine;
using System.Collections;
using System.Diagnostics;
public class TestTrace : MonoBehaviour {
void Start ()
{
TextWriterTraceListener myListener = new TextWriterTraceListener("TextWriterOutput.log", "myListener");
Trace.Listeners.Add(myListener);
Trace.WriteLine("Output via Trace.");
Trace.Flush();
myListener.WriteLine("Output direct from listener.");
myListener.Flush();
}
}
The given output to the trace file is:
Output direct from listener.
when I would expect:
Output direct from listener.
Output via Trace.
What am I doing wrong?
Comment
Answer by Caelin · Dec 27, 2012 at 12:04 AM
You are missing #define TRACE at the top of your file. To enable tracing or debugging you need to add a define for it. For debug it is just #define DEBUG.
Your answer
Follow this Question
Related Questions
How can I trace Alphabet 0 Answers
System Diagnostics Problem 1 Answer
More Layers? Selecting one out of 50+ GameObjects? 2 Answers