我有一个问题让我发疯。我有一个程序将错误消息保存到对象中的字符串中,然后将字符串写入 unloadContent() 中的文件。出于某种原因,我不断收到不支持的异常。这是 unloadContent() 中的代码:
if (debug.getContent().Length > 0)
{
saveErrors save = new saveErrors();
if (Directory.Exists(System.IO.Directory.GetCurrentDirectory() + "\\Errors")) ;
Directory.CreateDirectory(System.IO.Directory.GetCurrentDirectory() + "\\Errors");
save.save(System.IO.Directory.GetCurrentDirectory().ToString() + "\\Errors\\errorLog_" + (System.DateTime.Now.ToString().Replace("/", "_")).Replace(" ","") + ".txt");
}
这是类保存错误中的代码:
public class saveErrors
{
private string mess = debug.getContent();
public void save(string fileName)
{
Debug.WriteLine(fileName);
using (StreamWriter sw = new StreamWriter(fileName))
{
sw.Write(mess);
sw.Close();
}
}
}
我对 C# 还是有点陌生,所以任何帮助将不胜感激!
谢谢!