Logging
How do I log events?
This library uses an abstract base logging class that you must inherit from to describe how your application is going to log events. Usually, it's just a simple call to functions like Debug(), Info(), and so on.
Base loggers
That class that you'll need to inherit from in your custom logger class is called BaseLogger. However, this can be sometimes difficult, depending on how you want your application to log its events.
For this reason, for the sake of simplicity, we've created pre-built inherited classes in three different libraries.
Pre-built inherited classes
Aptivestigate.Serilog
SerilogLogger
Uses the Serilog library to log application events (you can use all available Serilog sinks)
Aptivestigate.Microsoft
MsLogger
Uses the Microsoft.Extensions.Logging library to log application events
You can create a new instance of any of the logger class mentioned in the above table (leave all arguments empty to print to the console, or specify a configurator)
Usage of the LogTools class
You can use the LogTools class that provides you with functions that allow you to easily log an event to different log levels using the base logger as the first parameter.
Functions for logging
Debug()
Debug messages
Info()
Informational messages
Warning()
Warning messages
Error()
Error messages
Fatal()
Fatal error messages
For exceptions, you must place an exception instance before the message but after the logger instance. This is so that you can format the string with ease.
You can also use the class functions to log application events to the logger.
Example of logging to the console
Here's a simple example of how to log to the console using the Serilog console sink (for all levels):
Last updated