Creating a custom logger
To demonstrate a custom logger, let's use a small simple logger I created that is able to colorize log entries with a specific log level in the console. This is called ColoredConsoleLogger
and will be added and created using LoggerProvider
, which we also need to write for ourselves. To specify the color and the log level to colorize, we need to add a configuration class.
In the next snippets, all three parts (Logger
, LoggerProvider
, and Configuration
) are shown:
- Let's create the configuration class of our logger. We will call it
ColoredConsoleLoggerConfiguration
. This class contains three properties to define –LogLevel
,EventId
, andColor
that can be set:public class ColoredConsoleLoggerConfiguration { Â Â Â Â public LogLevel LogLevel { get; set; } = Â Â Â Â Â Â LogLevel.Warning; Â Â Â Â public int EventId { get; set; } = 0; Â Â Â Â public ConsoleColor Color...