다른 프로그램에 대한 C# 스크립트를 테스트하는 프로그램이 있습니다. 스크립트가 Debug.Writeline 또는 Trace.Writeline 메서드를 사용할 수 있고 텍스트를 richtextbox에 쓸 수있을 때 여러 가지 다른 색의 텍스트가 필요합니다. 디버그는 주황색이고 Trace는 파랑입니다.Tracelistener의 추적 메시지와 디버그 메시지를 구분하십시오.
내가 스크립트가 실행 직후 나는
System.Diagnostics.Trace.Listeners.Add(new TextboxTraceListener(outputTxt, "ScriptTraceListener", Color.DarkBlue));
System.Diagnostics.Debug.Listeners.Add(new TextboxTraceListener(outputTxt, "ScriptDebugListener", Color.DarkOrange));
이 스크립트를 TextBoxTraceListener은
System.Diagnostics.Trace.Listeners.Remove("ScriptTraceListener");
System.Diagnostics.Debug.Listeners.Remove("ScriptDebugListener");
되어 실행 직전에
class TextboxTraceListener : TraceListener
{
private DebugRichTextbox output;
private Color textColor;
public TextboxTraceListener(DebugRichTextbox output) :this(output, "RichTextboxTraceListener", Color.Black)
{
}
public TextboxTraceListener(DebugRichTextbox output, string name, Color textColor)
{
this.Name = name;
this.output = output;
this.textColor = textColor;
}
public override void Write(string message)
{
Action write = delegate() { output.write(message, this.textColor); };
if (output.InvokeRequired)
{
IAsyncResult result = output.BeginInvoke(write);
output.EndInvoke(result);
}
else
{
write();
}
}
public override void WriteLine(string message)
{
Action writeLine = delegate() { output.writeLine(message, this.textColor); };
if (output.InvokeRequired)
{
IAsyncResult result = output.BeginInvoke(writeLine);
output.EndInvoke(result);
}
else
{
writeLine();
}
}
}
이 나타나는 것을를 Debug.Print 및 Trace.Writeline 메시지는 두 Listener에 의해 포착되고 메시지는 파란색과 오렌지색 richtextbox입니다. 메시지가 디버그 또는 TextBoxTraceListener의 추적에서 왔는지 알려주는 방법이 있습니까?
덕분에, Eoghan
추적 및 디버그는 추적 수신기와 디버그 모드에서 모두 읽을 수 있지만 디버그 수신기는 해제 모드에서 읽을 수 없습니다. 당신은 아마도 당신을 위해 해결할 수 있습니다, 추적을 사용하여 텍스트를 작성하고 자신의 클래스에서 색상을 구별 할 수있는 사용자 정의 클래스 (디버그 및 추적)를 제공합니다. –