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. 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 three pre-built inherited classes in three different libraries:
Aptivestigate.Log4Net
Uses the Log4Net library to log application events
You can create a new instance of the
Log4NetLogger
class (leave all arguments empty to print to the console, or specify a configurator)
Aptivestigate.Serilog
Uses the Serilog library to log application events (you can use all available Serilog sinks)
You can create a new instance of the
SerilogLogger
class (leave all arguments empty to print to the console, or specify a configurator)
Aptivestigate.NLog
Uses the NLog library to log application events
You can create a new instance of the
NLogLogger
class (leave all arguments empty to print to the console, or specify a configurator)
Here's a simple example of how to log to the console using the Serilog console sink (for all levels):
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. This class contains the following:
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.
Last updated