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 logger is called ColoredConsoleLogger
, and it will be created and added 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 in a new file called
CustomLogger.cs
in the same folder as theProgram.cs
file. Add the following using statement at the top of the file:namespace LoggingSample;
We will call it ColoredConsoleLoggerConfiguration
. This class contains three properties to define – LogLevel
, EventId
, and Color
– that can be set:
public class ColoredConsoleLoggerConfiguration { public LogLevel...