尝试从调试窗口写入外部文件:FAIL [英] Trying to Write from Debug window to External File: FAIL

查看:90
本文介绍了尝试从调试窗口写入外部文件:FAIL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试将调试窗口的最后5行写入外部文本文件。无论我做什么,都失败了。现在我遇到问题来自底部的第三行 sb.ToString()。Split('\ n')。Reverse()用红色下划线。错误读取:方法反向没有重载需要0个参数。我不知道这意味着什么,我不知道如何解决它。有人可以请帮助。



I have been trying for days to write the last 5 five lines of the debug window into an external text file. No matter what I do, it fails. Now I am having issues with the third line from the bottom "sb.ToString().Split('\n').Reverse()" underlined in red. The ERROR Reads: No overload for method 'Reverse' takes 0 arguments. I don't know what this means and I don't know how to fix it. Can someone please help.

using System;
using System.IO;
using System.Text;
using System.Diagnostics;
using System.Collections;
namespace Applica
{
    static class Program
    {
        static void Main(string[] args)
        {
            byte[] data = new byte[] {1,2,3,4,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,72,101,108,111,13,10};
            for (int i = 0; i < 28; i++)
            {
                //Console.WriteLine("{0}",data[i]);
                StringBuilder sb = new StringBuilder();
                StringWriter sw = new StringWriter(sb);
                TextWriterTraceListener myWriter = new TextWriterTraceListener(sw);
                Debug.Listeners.Add(myWriter);
                string output = string.Join("\n", sb.ToString().Split('\n').Reverse().Take(5).Reverse());
                string path = @"c:\temp\Log.txt";
                File.WriteAllText(path, output);
            }
        }
    }
}

推荐答案

你的问题是:你是正确使用 TextWriterTraceListener ,但它用于跟踪或调试输出。但是你没有给 Trace 写任何东西,所以没有什么可以捕获的。整个代码根本没有意义。



彻底阅读MSDN文档,注意代码示例,阅读所有相关内容以及 Trace 调试

https://msdn.microsoft.com/en-us/library/system.diagnostics.textwritertracelistener%28v=vs.110%29.aspx [ ^ ],

https://msdn.microsoft.com/en-us/library/system.diagnostics.trace%28v=vs.110%29.aspx [ ^ ],

https://msdn.microsoft.com/en-us/library/system.diagnostics.debug(V = vs.110)的.aspx [< a href =https://msdn.microsoft.com/en-us/library/system.diagnostics.debug(v=vs.110).aspx\"target =_ blanktitle =New Window> ^ ]。



-SA
Your problem is: you are correctly using TextWriterTraceListener, but it is used for tracing or debugging output. But you are not writing anything to Trace, so there is nothing to capture. The whole code simply makes no sense.

Read MSDN documentation thoroughly, pay attention for the code sample, read all about it and also Trace and Debug:
https://msdn.microsoft.com/en-us/library/system.diagnostics.textwritertracelistener%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.diagnostics.trace%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.diagnostics.debug(v=vs.110).aspx[^].

—SA


这篇关于尝试从调试窗口写入外部文件:FAIL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆