<PackageReference Include="NUnit" Version="4.5.0" />

TextCapture

public class TextCapture : TextWriter
The TextCapture class intercepts console output and writes it to the current execution context, unless it corresponds with an ad-hoc test context. In an ad-hoc context, the output is written to a default destination, normally the original destination of the intercepted output.
public TextCapture(TextWriter defaultWriter)

Construct a TextCapture object