# ConsoleLog

### SetUp

Include `Logging.Console` library in project:

```csharp
using Vostok.Logging.Console;
```

&#x20;An standard `ILog` is created using  `ConsoleLog`:

```csharp
var log = new ConsoleLog();
```

Create an event. Let it be an error message:

```csharp
log.Error("Error number 1");
```

You can add as many events as you want:&#x20;

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

To observe the result, add `ConsoleLog.Flush()` or `ConsoleLog.FlushAsync()`.&#x20;

Result:

```aspnet
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:

```csharp
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&#x20;

Console log's configuration passes in code (the example above).&#x20;

### Settings

This parameters are adjusted in `ConsoleLogSettings`:

| Parameters                                                                                                                                                     | Description                                                                                                             |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| <p></p><p><a href="https://github.com/vostok/logging.console/blob/master/Vostok.Logging.Console/ConsoleLogSettings.cs"><strong>OutputTemplate</strong></a></p> | <p></p><p>Used to render log messages. For more information, see <a href="../../syntax#output-template">Syntax</a>.</p> |
| <p></p><p><a href="https://github.com/vostok/logging.console/blob/master/Vostok.Logging.Console/ConsoleLogSettings.cs"><strong>FormatProvider</strong></a></p> | <p> <br>If specified, this IFormatProvider will be used when formatting log events.</p>                                 |
| <p></p><p><a href="https://github.com/vostok/logging.console/blob/master/Vostok.Logging.Console/ConsoleLogSettings.cs"><strong>ColorMapping</strong></a></p>   | <p></p><p>Mapping of log levels to text color in console</p>                                                            |
| <p></p><p><a href="https://github.com/vostok/logging.console/blob/master/Vostok.Logging.Console/ConsoleLogSettings.cs"><strong>ColorsEnabled</strong></a></p>  | <p></p><p>Specifies whether the console log must colorize text depending on the log level</p>                           |
