ConsoleLog

A log which outputs events to console.

SetUp

Include Logging.Console library in project:

using Vostok.Logging.Console;

An standard ILog is created using ConsoleLog:

var log = new ConsoleLog();

Create an event. Let it be an error message:

log.Error("Error number 1");

You can add as many events as you want:

for (int i = 1; i <= 100; i++)
{
    log.Error("Error number {0}",i);
}

To observe the result, add ConsoleLog.Flush() or ConsoleLog.FlushAsync().

Result:

2018-11-06 17:36:04,702 ERROR Error number 1
...
2018-11-06 17:36:04,789 ERROR Error number 100

First Usage

Configure a log and use ConsoleLogSettings for it. For example, you can change output template. The log would show only time stamp and message. Leave the rest of the code the same:

var consoleLog = new ConsoleLog(new ConsoleLogSettings
{
    OutputTemplate = OutputTemplate.Parse("{TimeStamp:hh:mm:ss} {Message}{NewLine}")
});

for (int i = 1; i <= 100; i++)
{
    consoleLog.Error("Error number {0}",i);
}

ConsoleLog.Flush();

Result:

06:06:51 Error number 1
...
06:06:51 Error number 100

Configurations

Console log's configuration passes in code (the example above).

Settings

This parameters are adjusted in ConsoleLogSettings:

Parameters

Description

Used to render log messages. For more information, see Syntax.

If specified, this IFormatProvider will be used when formatting log events.

Mapping of log levels to text color in console

Specifies whether the console log must colorize text depending on the log level

Last updated