gitlabEdit

list-treeLogging

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.

chevron-rightPre-built inherited classeshashtag
Package
Class
Description

Aptivestigate.Log4Net

Log4NetLogger

Uses the Log4Netarrow-up-right library to log application events

Aptivestigate.Serilog

SerilogLogger

Uses the Serilogarrow-up-right library to log application events (you can use all available Serilog sinksarrow-up-right)

Aptivestigate.NLog

NLogLogger

Uses the NLogarrow-up-right library to log application events

Aptivestigate.ZLogger

ZeeLogger

Uses the ZLoggerarrow-up-right library to log application events

Aptivestigate.Microsoft

MsLogger

Uses the Microsoft.Extensions.Loggingarrow-up-right library to log application events

circle-info

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.

chevron-rightFunctions for logginghashtag
Function
Description

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.

circle-info

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