需要知道如何创建文件名和位置以保存以下内容 [英] Need to know how to create file name and location to save the following

查看:71
本文介绍了需要知道如何创建文件名和位置以保存以下内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

黑色调试窗口显着减慢了我的速度,我只对调试窗口的最后5行感兴趣。我一直在寻找一种方法将最后5行保存到外部文件。有人给我写了这个解决方案,却忽略了添加我想要的最重要的部分。他们没有告诉我如何创建文件名和位置来保存调试屏幕的最后5行。





The black debug window was slowing me down significantly and I was only interested in the last 5 lines of the debug window. I was looking for a way to save the last 5 lines to an external file. Someone wrote me this solution but neglected to add the most important part of what I was looking for. They didn't show me how to create a file name and and location to save the last 5 lines of the debug screen.


             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());

推荐答案

您可以使用 File.WriteAllText [ ^ ]方法将字符串写入给定路径中的文件,例如:

You can use File.WriteAllText[^] method to write string to a file in given path, for example:
string path = @"c:\temp\Log.txt";
File.WriteAllText(path, output);


这篇关于需要知道如何创建文件名和位置以保存以下内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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