Captin.ConsoleIntercept 2.0.0

Capture and observe Console output written by methods such as Console.WriteLine. It also leaves the original console output stream intact.

Install-Package Captin.ConsoleIntercept -Version 2.0.0
dotnet add package Captin.ConsoleIntercept --version 2.0.0
<PackageReference Include="Captin.ConsoleIntercept" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Captin.ConsoleIntercept --version 2.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Console Out Observer

Capture and observe Console output written by methods such as Console.WriteLine.
It also leaves the original console output stream intact.

This is useful for temporarily capturing logging during integration or unit
testing of your own code.

This is NOT useful for permanent silencing of Console.Out.

This is NOT useful for capturing output of an externally started program. For
that you will want to look into usage
of System.Diagnostics.Process.

Installing / Getting started

  1. Install the Captin.ConsoleIntercept NuGet package
  2. Add the NuGet package to your project
  3. Observe Console output in a test
     using Captin.ConsoleIntercept;
     using Xunit;
    
     [Fact]
     public void Test1()
     {
     	System.Console.Write("not observed");
     	using(var logged = ConsoleOut.Observe()) {
     		System.Console.Write("log (sent to real console too)");
     		Assert.Equal("log (sent to real console too)", logged.ToString());
     	}
     	System.Console.Write("not observed (and real console is restored)");
     }
    

Features

  • Capture console output cleanly with a using statement
      using(var logged = ConsoleOut.Observe()) {
      	...
      }
    
  • Nested using statements supported
      using(var a = ConsoleOut.Observe()) {
      	Console.WriteLine("a");
      	using(var b = ConsoleOut.Observe()) {
      		Console.WriteLine("a and b");
      	}
      }
    
  • Leaves standard Console.Out intact even when observing
      using(var logged = ConsoleOut.Observe()) {
      	Console.WriteLine("'logged' (and original console too)");
      }
    
  • NOT thread safe. Running tests in parallel that both capture output may cause
    observing logs from Test1 to show up in Test2

Developing

Here's a brief intro about what a developer must do in order to start developing
the project further:

  1. Clone the project
     git clone https://github.com/captin411/Captin.ConsoleIntercept.git
    
  2. Open the solution in Visual Studio.

Contributing

Pull requests are welcome.

If you want to contribute, please fork the repository and use a feature branch.

It would be AWESOME if you add in a test to cover any new behavior or bug fixes
that you might have.

Links

  • Project: https://github.com/captin411/Captin.ConsoleIntercept
  • Nuget Package: https://www.nuget.org/packages/Captin.ConsoleIntercept/

Licensing

The code in this project is licensed under MIT license.

Console Out Observer

Capture and observe Console output written by methods such as Console.WriteLine.
It also leaves the original console output stream intact.

This is useful for temporarily capturing logging during integration or unit
testing of your own code.

This is NOT useful for permanent silencing of Console.Out.

This is NOT useful for capturing output of an externally started program. For
that you will want to look into usage
of System.Diagnostics.Process.

Installing / Getting started

  1. Install the Captin.ConsoleIntercept NuGet package
  2. Add the NuGet package to your project
  3. Observe Console output in a test
     using Captin.ConsoleIntercept;
     using Xunit;
    
     [Fact]
     public void Test1()
     {
     	System.Console.Write("not observed");
     	using(var logged = ConsoleOut.Observe()) {
     		System.Console.Write("log (sent to real console too)");
     		Assert.Equal("log (sent to real console too)", logged.ToString());
     	}
     	System.Console.Write("not observed (and real console is restored)");
     }
    

Features

  • Capture console output cleanly with a using statement
      using(var logged = ConsoleOut.Observe()) {
      	...
      }
    
  • Nested using statements supported
      using(var a = ConsoleOut.Observe()) {
      	Console.WriteLine("a");
      	using(var b = ConsoleOut.Observe()) {
      		Console.WriteLine("a and b");
      	}
      }
    
  • Leaves standard Console.Out intact even when observing
      using(var logged = ConsoleOut.Observe()) {
      	Console.WriteLine("'logged' (and original console too)");
      }
    
  • NOT thread safe. Running tests in parallel that both capture output may cause
    observing logs from Test1 to show up in Test2

Developing

Here's a brief intro about what a developer must do in order to start developing
the project further:

  1. Clone the project
     git clone https://github.com/captin411/Captin.ConsoleIntercept.git
    
  2. Open the solution in Visual Studio.

Contributing

Pull requests are welcome.

If you want to contribute, please fork the repository and use a feature branch.

It would be AWESOME if you add in a test to cover any new behavior or bug fixes
that you might have.

Links

  • Project: https://github.com/captin411/Captin.ConsoleIntercept
  • Nuget Package: https://www.nuget.org/packages/Captin.ConsoleIntercept/

Licensing

The code in this project is licensed under MIT license.

  • .NETStandard 2.0

    • No dependencies.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
2.0.0 75 2/18/2020
1.0.0 139 2/17/2020