使用.NET核心获取可执行目录的问题?

时间:2018-03-10 13:54:58

标签: c# .net

  

System.IO.DirectoryNotFoundException:'无法找到部分内容   路径   'C:\用户\管理员\发展\项目31 \ BIN \调试\ netcoreapp2.0 \资源\记录\的debug.log''

这发生在以下一行......

var fileWriter = new StreamWriter(executionPath + "/resources/logging/" + file, true);

完整代码:

private static void LogToFile(string file, string content)
{
    var executionPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
    var fileWriter = new StreamWriter(executionPath + "/resources/logging/" + file, true);

    fileWriter.WriteLine(content);
    fileWriter.Close();
}

问题是,它进入netcoreapp2.0文件夹,当我想要它进入时是调试。

我可以备份1个目录,但我知道如果我在.NET框架中使用此代码而不是.NET核心,由于.NET框架没有在netcoreapp2.0中运行调试,它将再次中断

0 个答案:

没有答案