title: Create directory if not exists
body: <p>I want to make logs for differenct actions. I create a new file every day with the date as file name. Now, if the directory doesnt exist, I want the system to make the directory for me. I have searched for this topic and all answers come to the same thing: use <code>Directory.CreateDirectory(FilePath);</code>. However this doesnt seem to work. Might be missing something obvious.</p>
  
  <p>Here's the code:</p>
  
  <pre><code>public class ElderlyHomeLog : ILog
      {
          private const string FilePath = "/Logs/WZCLogs/";
          public void MakeLog(string text)
          {
              if (!Directory.Exists(FilePath))
              {
                  Directory.CreateDirectory(FilePath);
              }
              string logFile = DateTime.Now.ToString("ddMMyyyy") + ".txt";
              if (!File.Exists(HostingEnvironment.ApplicationPhysicalPath + FilePath + logFile))
              {
                  FileStream f = File.Create(HostingEnvironment.ApplicationPhysicalPath + FilePath + logFile);
                  f.Close();
              }
  
              using (StreamWriter sw = new StreamWriter(HostingEnvironment.ApplicationPhysicalPath + FilePath + logFile, true))
              {
                  sw.WriteLine(text);
                  sw.Close();
              }
          }
      }
  </code></pre>
  
  <p>Error message:</p>
  
  <blockquote>
    <p>An exception of type 'System.IO.DirectoryNotFoundException' occurred
    in mscorlib.dll but was not handled in user code</p>
    
    <p>Additional information: Could not find a part of the path
    'C:\Users\***\Source\Repos\Project\ProjectName\Logs\WZCLogs\31032016.txt'.</p>
  </blockquote>