Console
A complete C# mirror of the browser console: log levels, assertions, counters, timers, groups, tables, stack traces and profiling. Open your DevTools console (F12) - that is where everything below lands.
@inject Bit.Butil.Console consoleMDN reference
The five standard severity levels, each styled and filterable in DevTools. All accept any number of values, including objects.
await console.Log("General output:", value);
await console.Info("Informative:", value);
await console.Warn("Warning:", value);
await console.Error("Error:", value);
await console.Debug("Debug level:", value);Assert logs only when its condition is false. Dir prints an interactive property listing of an object, while Dirxml renders a DOM node as an expandable HTML tree.
await console.Assert(items.Count > 0, "The list should never be empty!");
await console.Dir(someObject);
await console.Dirxml(elementReference);Renders an array or object as a sortable table in DevTools; the optional second argument restricts which columns are shown.
var people = new[]
{
new { Name = "Ada", Role = "Engineer" },
new { Name = "Grace", Role = "Admiral" },
};
await console.Table(people);
await console.Table(people, new[] { "Name" }); // only the Name columnCount logs how many times it has been called with a given label; CountReset sets that counter back to zero.
await console.Count("clicks"); // clicks: 1
await console.Count("clicks"); // clicks: 2
await console.CountReset("clicks"); // back to 0Start a named timer, log intermediate readings, and stop it to print the total elapsed time. TimeStamp additionally drops a marker into the browser's performance timeline.
await console.Time("load");
await console.TimeLog("load"); // load: 102 ms
await console.TimeEnd("load"); // load: 341 ms - timer ended
await console.TimeStamp("checkpoint");Indents subsequent output into nested, collapsible groups. GroupCollapsed starts the group closed; GroupEnd steps back out one level.
await console.Log("Outer level");
await console.Group("Details");
await console.Log("Inside the group");
await console.GroupCollapsed("Collapsed by default");
await console.Log("Hidden until expanded");
await console.GroupEnd();
await console.GroupEnd();Trace prints the current stack trace. Profile and ProfileEnd start and stop the browser's built-in JavaScript profiler under an optional name.
await console.Trace("How did we get here?");
await console.Profile("render");
// ... the work you want profiled ...
await console.ProfileEnd("render");Wipes the DevTools console (some browsers keep a 'Console was cleared' notice).
await console.Clear();API reference
Task Assert(bool? condition, params object?[]? args)Task Clear()Task Count(string? label = null)Task CountReset(string? label = null)Task Debug(params object?[]? args)Task Dir(object? item, object? options = null)Task Dirxml(params object?[]? args)Task Error(params object?[]? args)Task Group(params object?[]? args)Task GroupCollapsed(params object?[]? args)Task GroupEnd()Task Info(params object?[]? args)Task Log(params object?[]? args)Task Profile(string? name = null)Task ProfileEnd(string? name = null)Task Table(object? data, object? properties = null)Task Time(string? label = null)Task TimeEnd(string? label = null)Task TimeLog(string? label = null, params object?[]? args)Task TimeStamp(string? label = null)Task Trace(params object?[]? args)Task Warn(params object?[]? args)