.NET

How to instrument Tailed from .NET with just two lines of code.

Setup

Install the Tailed.Console nuget package:

dotnet add package Tailed.Console

Basic Usage

You will need to create a new ConsoleSession and then start it:

using Tailed.Console;

// The magic two lines!
await using var session = new ConsoleSession();
session.Start();

Console.WriteLine("This will be streamed to tailed.live");

// This is optional - StopAsync() will be called when disposing the session, if it
// hasn't been called already.
await session.StopAsync();
Console.WriteLine("This won't be streamed to tailed.live");

Any logging framework that has a console output (e.g. Microsoft.Extensions.Logging.Console or Serilog.Sinks.Console) can be used together with the above configuration code.

Customization Options

The constructor on the ConsoleSession allows you to customize:

  1. Whether only ANSI colors are honored (the default) or whether Console.ForegroundColor and Console.BackgroundColor should also be honored. More fine-grained control of color can be achieved using ANSI. The Pastel nuget package is recommended to facilitate colorization. Ensure you're using a console window that handles ANSI colors (e.g. Windows Terminal as opposed to the traditional Command Prompt).

  2. A custom hostname to use in the session URL (instead of tailed.live).

If you choose to call StopAsync() yourself, an override exists that allows you to specify the number of milliseconds to wait to allow buffers to be flushed. This defaults to 2000 ms.

Last updated