0

Because I don't have any Windows Server with IIS on which I can test functionality of the app I want to ask if this code below would work the way I intended - web app writes something to console and I need to save what is written in console to a specific file. I am testing it locally on my laptop with ISS Express installed by Visual Studio 2013.

Is IIS Express the same as IIS on Windows Server so I can use this piece of code below?

using (var consoleWriter = new StreamWriter(
            new FileStream(_tempOutputFileName, 
                            FileMode.Create, FileAccess.Write)))
{
    Console.SetOut(consoleWriter);
    //do some work here with output to console
}


var standardOutput = 
       new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true };
Console.SetOut(standardOutput);

Edit : I can't write to file directly because I need to catch what is written to console by 3rd party library I am using.

2
  • Why don't you write directly to the file? Commented Sep 30, 2014 at 12:49
  • I can't since I am using external library and the library writes to console and I need to get what the library writes to console. Commented Sep 30, 2014 at 12:53

1 Answer 1

1

Consider using a logging framework, like log4net and redirect Console output eg. like this.

In log4net you have a lot of appenders , databases etc.

Writing to a file in a IIS enviroment can have security issues.

Sign up to request clarification or add additional context in comments.

1 Comment

Seems I can't use log4net because I am not the one to write to the console but 3rd party app and I couldn't find the way how to log console output from library's methods.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.