<legend id='06N5t'><style id='06N5t'><dir id='06N5t'><q id='06N5t'></q></dir></style></legend>
    • <bdo id='06N5t'></bdo><ul id='06N5t'></ul>

    <small id='06N5t'></small><noframes id='06N5t'>

  1. <i id='06N5t'><tr id='06N5t'><dt id='06N5t'><q id='06N5t'><span id='06N5t'><b id='06N5t'><form id='06N5t'><ins id='06N5t'></ins><ul id='06N5t'></ul><sub id='06N5t'></sub></form><legend id='06N5t'></legend><bdo id='06N5t'><pre id='06N5t'><center id='06N5t'></center></pre></bdo></b><th id='06N5t'></th></span></q></dt></tr></i><div id='06N5t'><tfoot id='06N5t'></tfoot><dl id='06N5t'><fieldset id='06N5t'></fieldset></dl></div>

    1. <tfoot id='06N5t'></tfoot>

    2. 跟踪侦听器以写入文本框(WPF 应用程序)

      时间:2023-06-10

      <small id='OHLAk'></small><noframes id='OHLAk'>

        <bdo id='OHLAk'></bdo><ul id='OHLAk'></ul>
        <i id='OHLAk'><tr id='OHLAk'><dt id='OHLAk'><q id='OHLAk'><span id='OHLAk'><b id='OHLAk'><form id='OHLAk'><ins id='OHLAk'></ins><ul id='OHLAk'></ul><sub id='OHLAk'></sub></form><legend id='OHLAk'></legend><bdo id='OHLAk'><pre id='OHLAk'><center id='OHLAk'></center></pre></bdo></b><th id='OHLAk'></th></span></q></dt></tr></i><div id='OHLAk'><tfoot id='OHLAk'></tfoot><dl id='OHLAk'><fieldset id='OHLAk'></fieldset></dl></div>

        1. <legend id='OHLAk'><style id='OHLAk'><dir id='OHLAk'><q id='OHLAk'></q></dir></style></legend>
              • <tfoot id='OHLAk'></tfoot>
                  <tbody id='OHLAk'></tbody>
                本文介绍了跟踪侦听器以写入文本框(WPF 应用程序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                对于我的 WPF 应用程序,我使用 TextWriterTraceListener 将日志记录到文本文件.如何将 Trace 输出也显示到文本框?

                For my WPF application I do logging to a text file using a TextWriterTraceListener. How can I also display the Trace output to a textbox?

                推荐答案

                我在 C# winforms 中使用这个,应该很容易调整到 wpf

                I use this for C# winforms, should be easily adjustable to wpf

                public class MyTraceListener : TraceListener
                {
                    private TextBoxBase output;
                
                    public MyTraceListener(TextBoxBase output) {
                        this.Name = "Trace";
                        this.output = output;
                    }
                
                
                    public override void Write(string message) {
                
                        Action append = delegate() {
                            output.AppendText(string.Format("[{0}] ", DateTime.Now.ToString()));
                            output.AppendText(message); 
                        };
                        if (output.InvokeRequired) {
                            output.BeginInvoke(append);
                        } else {
                            append();
                        }
                
                    }
                
                    public override void WriteLine(string message) {
                        Write(message + Environment.NewLine);
                    }
                }
                

                像这样使用它

                TraceListener debugListener = new MyTraceListener (theTextBox);
                Debug.Listeners.Add(debugListener);
                Trace.Listeners.Add(debugListener);
                

                记得 Trace/Debug.Listeners.Remove(debugListener);当你不再需要它时.

                Remember to Trace/Debug.Listeners.Remove(debugListener); when you don't need it anymore.

                这篇关于跟踪侦听器以写入文本框(WPF 应用程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何将 .NET 刻度转换为 python 日期时间? 下一篇:在 TextBox 中使特定文本加粗

                相关文章

                  <bdo id='ES8mC'></bdo><ul id='ES8mC'></ul>

                <small id='ES8mC'></small><noframes id='ES8mC'>

              • <legend id='ES8mC'><style id='ES8mC'><dir id='ES8mC'><q id='ES8mC'></q></dir></style></legend>
                <tfoot id='ES8mC'></tfoot>
              • <i id='ES8mC'><tr id='ES8mC'><dt id='ES8mC'><q id='ES8mC'><span id='ES8mC'><b id='ES8mC'><form id='ES8mC'><ins id='ES8mC'></ins><ul id='ES8mC'></ul><sub id='ES8mC'></sub></form><legend id='ES8mC'></legend><bdo id='ES8mC'><pre id='ES8mC'><center id='ES8mC'></center></pre></bdo></b><th id='ES8mC'></th></span></q></dt></tr></i><div id='ES8mC'><tfoot id='ES8mC'></tfoot><dl id='ES8mC'><fieldset id='ES8mC'></fieldset></dl></div>