How to save the output of a console application

后端 未结 6 1130
有刺的猬
有刺的猬 2021-01-11 19:12

I need advice on how to have my C# console application display text to the user through the standard output while still being able access it later on. The actual feature I w

6条回答
  •  天涯浪人
    2021-01-11 20:18

    I would say mimic the diagnostics that .NET itself uses (Trace and Debug).

    Create a "output" class that can have different classes that adhere to a text output interface. You report to the output class, it automatically sends the output given to the classes you have added (ConsoleOutput, TextFileOutput, WhateverOutput).. And so on.. This also leaves you open to add other "output" types (such as xml/xslt to get a nicely formatted report?).

    Check out the Trace Listeners Collection to see what I mean.

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题