This library provides some simple support for logging, with output sent to the console, files, a (reactive) IObserver,
or any other custom sink. Configuration is done using a simple text file or a Configurer.
- Fixed TargetPlatforms to net6.0-windows and net8.0-windows, since we don't depend on Windows 10 or 11 specific stuff.
- Fixed TargetPlatforms for the tests.
- Made the library multi-platform, by adding net8.0-windows7.0.
Log messages (Rakis.Logging.LogEntry) are objects containing:
- A timestamp,
- A source, which is typically the name of the logger object,
- A level, showing how important the entry is, and
- An actual message.
Levels are the common Log-levels used in most environments, from low to high:
| Level | Description |
|---|---|
TRACE |
Detailed logging to show internal workings. This level is normally used only for detailed debugging of the code using it, because it contains so much information that producing it negatively impacts performance. Typically only the authors of the code would use this level. |
DEBUG |
Normal debugging information. This level might be used also by end-users to provide additional information when trying to explain behavior. That said, like TRACE, it may affect performance enough that you'd normally leave this off. |
INFO |
Informational messages showing important hints about the code's behavior. This is the default level, although it does not provide information essential to the operation of the application. |
WARN |
Important messages about unexpected or unwanted situations that the code can easily compensate for, but the user should be aware of. |
ERROR |
Things that should not have happened, but the code was able to recover from. |
FATAL |
An error that could not be recovered from. Normally this would announce an abnormal abort of the application. |
Logging is done using an Rakis.Logging.ILogger conforming object, which encapsulates:
- A name, which is a structured name like a fully qualified Class name, like "
Rakis.Logging.Logger," - A sink, which is the object actually writing the logs to whatever has been chosen, and
- A threshold, below which messages are ignored.
You can obtain a logger with the static GetLogger method, which you pass a name or a type:
private static ILogger logger = Logger.GetLogger(typeof(MyClass));
private static ILogger auditLogger = Logger.GetLogger("AUDIT");To produce logging output, use one of the "leveled" loggers:
logger.Info?.Log("Application starting up");
logger.Trace?.Log($"Application started at {DateTime.Now}.");The levels will be a null-reference if they fall below the threshold, so none of the actual logging is performed if the output is filtered out. If you have multiple entries you'd like to produce or need some preperatory work, you can check if a level is enabled:
if (logger.IsEnabled(LogLevel.DEBUG)) { ... }or
if (logger.IsDebugEnabled) {... }By default, logging will be sent to the console with a threshold of INFO.
You can use configurers