title: Writing console lines to file
body: <p>I have a console app in c# and am trying to make it so that all the lines in the console are written into a file. I have tried using a streamwriter.</p>
  
  <pre><code>using (StreamWriter writer = new StreamWriter(@"location", true))
  {
      writer.WriteLine(Console.ReadLine());
  }
  </code></pre>
  
  <p>But using these methods the output text file was still empty. Am I missing something?</p>
  
  <p>Solution: 
  write this at the place where you want to start recording the text</p>
  
  <pre><code>        Console.Clear();
          StringWriter sw = null;
          sw = new StringWriter();
          Console.SetOut(sw);
  </code></pre>
  
  <p>write this at the end</p>
  
  <pre><code>    string s = sw.GetStringBuilder().ToString();
          File.WriteAllText(@"file location", s);
  </code></pre>
  
  <p>text wouldn't display on console if I do that but does not matter in this case.</p>