保存错误日志的路径有问题 [英] Problem with the path for saving error log

查看:95
本文介绍了保存错误日志的路径有问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将错误日志保存在文本文件中。但我收到错误



I am trying to save Error logs in text file. But i am getting error

Illegal characters in path.





路径似乎没问题。





Path seems ok .

private ExceptionHandler()
        {
            string exePath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            _StreamWriter = new StreamWriter(Path.Combine(exePath, "E:\test.txt"));
        }





我的尝试:



我在E盘中有一个test.txt文件。路径还可以,但我收到错误



What I have tried:

I have a test.txt file in E drive . The path is ok but i am getting error

Illegal characters in path

推荐答案

in E:\test.txt \t 具有特殊含义。

您需要使用

in "E:\test.txt", \t have special meaning.
you need to use
"E:\\test.txt"



这是C语言家庭行为,'\'用于特殊字符。


It is C language family behavior, '\' is used for special chars.


除了在另一个解决方案中提到的内容,您尝试将完全限定的路径附加到另一个完全限定的路径。你不能这样做。



此外,你从location获得的路径包括可执行文件名。这也不适合你。如果你想要启动.EXE文件夹的路径,你需要首先删除路径末尾的.EXE。

In addition to what was mentioned in the other solution, you are trying to append a fully qualified path to another fully qualified path. You can't do that.

Also, the path you got from location includes the executable name. That's not going to work for you either. If you want the path to the folder the .EXE was launched from, you need to remove the .EXE at the end of the path first.
var exePath = Assembly.GetEntryAssembly().Location;
var folder = Path.GetDirectoryName(exePath);
var logPath = Path.Combine(folder, "test.txt");


这篇关于保存错误日志的路径有问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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