Tell me, is there a way to copy all the data from the console, at the end of the application to the file?

Yes, you can of course every time something is output to the console in parallel to write to a file, but is it possible in one fell swoop to write the final result from the console to a file?

    1 answer 1

    You can use the Log4Net library.

    It can write simultaneously to a file and a console, as well as to any other place (for example, a database), has flexible settings, supports multithreading.

    And do not reinvent the wheel.

    You can also do this:

    static void Main(string[] args) { Trace.Listeners.Clear(); TextWriterTraceListener twtl = new TextWriterTraceListener(Path.Combine(Path.GetTempPath(), AppDomain.CurrentDomain.FriendlyName)); twtl.Name = "TextLogger"; twtl.TraceOutputOptions = TraceOptions.ThreadId | TraceOptions.DateTime; ConsoleTraceListener ctl = new ConsoleTraceListener(false); ctl.TraceOutputOptions = TraceOptions.DateTime; Trace.Listeners.Add(twtl); Trace.Listeners.Add(ctl); Trace.AutoFlush = true; Trace.WriteLine("The first line to be in the logfile and on the console."); } 

    Taken from here:

    https://stackoverflow.com/questions/420429/mirroring-console-output-to-a-file

    • Yes, yes, and there and there. - Pyrejkee
    • @ PyrejkeePureshkin Like, corrected. - iluxa1810 pm