.NET
How to instrument Tailed from .NET with just two lines of code.
Setup
Install the Tailed.Console nuget package:
dotnet add package Tailed.ConsoleBasic 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");Choose the right point at which to start the ConsoleSession. For example, if you're asking the user for credentials or a connection string, you'll want to start the session after that point so you don't stream those details to everyone viewing the session.
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:
Whether only ANSI colors are honored (the default) or whether
Console.ForegroundColorandConsole.BackgroundColorshould also be honored. More fine-grained control of color can be achieved using ANSI. ThePastelnuget 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).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