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...