1

System.IO.DirectoryNotFoundException: 'Could not find a part of the path 'C:\Users\admin\development\project31\bin\Debug\netcoreapp2.0\resources\logging\debug.log'.'

This happens on the following line...

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

Full code:

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

The issue is, its going into the netcoreapp2.0 folder, when all I want it to go into is the debug.

I could just back up 1 directory, but I know if I use this code in .NET framework not .NET core it will break again due to .NET framework not running debug in netcoreapp2.0

zades
  • 11
  • 2
  • 1
    Does this directory exists ? If you open file explorer and you go to the folder _C:\Users\admin\development\project31\bin\Debug\netcoreapp2.0\resources_ do you see there any folder with the name logging? – Christos Mar 10 '18 at 13:55
  • The issue is, its going into the `netcoreapp2.0` folder, when all I want it to go into is the debug folder. But I know if I just back 1 directory, when I use this code in .NET framework not .NET core it will break again. – zades Mar 10 '18 at 13:57
  • That you want is to access a file in a directory. If the directory does not exist, you would get a _System.IO.DirectoryNotFoundException_. So the question you should first answer, is if this directory exists. – Christos Mar 10 '18 at 13:59
  • 1
    @zades: That's simply not how .NET Core builds things - the output path includes the target framework (for which I'm personally very grateful). That can easily be found by having a look in the directory in question. It's not really clear *why* you'd need it to be in bin/Debug to start with. Perhaps you should be configuring the directory in a different way? (I wouldn't want any important output in a `bin` directory which I'd regard as transient, to be deleted whenever I want to do a clean build...) – Jon Skeet Mar 10 '18 at 13:59

0 Answers0