title: C# How to capture input from pipeline from continuous stream source
body: <p>I have a service that runs as a console app and outputs to stdout and stderr streams to the console.  The developers don't want to add any logging capabilities since it was mainly designed for linux world and they have tools like logroate and other means already but don't care about the windows port.  I want to redirect those streams into a log and I'm able to do it like this:
  service.exe 2&gt;&amp;1 &gt;&gt; service.log</p>
  <p>But if I leave this running this log will grow out of control.  So I tried using something called logrotateWin but it needs to rename the log file and I get access denied since its in use.  So I'm trying to write another app that can write to logfile and rotate it based once a day and only keep last n logs.</p>
  <p>I want to be able to run it like:
  service.exe 2&gt;&amp;1 | logrotater.exe</p>
  <p>So I'm trying to write logrotater with the following code but it seems to fail to read the stream from the pipeline.  It can read the stream if it stops like from a simple echo &quot;test&quot; command source, but not from service.exe that continuously keeps streaming data out.  Any suggestions?</p>
  <p>So this works:
  echo &quot;test&quot; | logrotater.exe</p>
  <p>But this doesn't work:
  service.exe 2&gt;&amp;1 | logrotater.exe</p>
  <pre><code>static void Main(string[] args) {
      Console.SetIn(new StreamReader(Console.OpenStandardInput(8192))); // This will allow input &gt;256 chars
      while (Console.In.Peek() != -1) {
          string input = Console.In.ReadLine();
          Console.WriteLine(&quot;Data read was &quot; + input);
      }
  }
  </code></pre>