var consoleLog = new ConsoleLog();
var configuredConsoleLog = new ConsoleLog(new ConsoleLogSettings());
- Customizable per-level message colors.
Logmethod is nonblocking: log events are placed into an internal queue, grouped into batches and efficiently written to console output stream in the background.
ConsoleLogSettingshave to offer:
All configuration parameters are optional.
There's also static global configuration that affects all
ConsoleLoginstances in the application. It is accessed as follows:
This configuration exposes following parameters worth mentioning:
Note that changes in these global configuration parameters only take effect if performed before any actual logging.
- Keep in mind that log messages are rendered in the background. Use
ConsoleLogto ensure that all logged events have been written to console when the application shuts down.
- Internal queue with limited capacity implies that log messages may be lost in the event of overflow (see guarantees section for more on this topic). Use
EventsLostproperty of a single
ConsoleLoginstance or static
TotalEventsLostproperty to check if any events have been discarded.
- If any log events are lost due to internal queue overflow,
ConsoleLogemits a special diagnostic message that looks like this:
- [ConsoleLog] Buffer overflow. 100 log events were lost (events queue capacity = 50000).
There are certain scenarios where it's not feasible to use an asynchronous log, such as logging in unit tests or simple console utilities. These use cases are better served by an alternative synchronous implementation that writes to console immediately in
var synchronousLog = new SynchronousConsoleLog();
It's performance is vastly inferior to that of
ConsoleLogdue to lack of buffering, but it removes the need to flush and works well in test environments where
Console.Outcannot be safely cached.