DefaultLoggerService

Wisej.AI.Services.DefaultLoggerService

Namespace: Wisej.AI.Services

Assembly: Wisej.AI (3.5.0.0)

Provides a default implementation of the ILoggerService for logging messages and exceptions.

public class DefaultLoggerService : ILoggerService

This class implements the ILoggerService interface, offering methods to log messages and exceptions at various trace levels.

Constructors

DefaultLoggerService()

Initializes a new instance of DefaultLoggerService.

Methods

Log(level, context, message, arguments)

Provides functionality to log messages at various trace levels.

Parameter
Type
Description

level

The trace level at which the message should be logged.

context

A string representing the name of the class and the method that called the logger.

message

The message to be logged. This parameter supports composite formatting.

arguments

An array of objects to format the message with. This parameter is optional.

This method allows for logging messages with different severity levels, facilitating the tracking of information, warnings, and errors. Depending on the level specified, the method will route the message to the appropriate logging method. The supported trace levels are:

  • Off: No logging is performed.

  • Info: Logs informational messages.

  • Error: Logs error messages.

  • Warning: Logs warning messages.

Here is an example of how to use the Log method:


  Log(TraceLevel.Info, "Starting process with ID {0}", processId);
  Log(TraceLevel.Warning, "Disk space is low on drive {0}", driveName);
  Log(TraceLevel.Error, "Failed to connect to server. Error: {0}", errorMessage);

Log(level, context, exception)

Logs an exception at a specified trace level.

Parameter
Type
Description

level

The trace level at which the exception should be logged.

context

A string representing the name of the class and the method that called the logger.

exception

The exception to be logged.

This method is designed to log exceptions, allowing for a structured approach to error handling and diagnostics. The level parameter determines the severity of the log entry. Example usage of the method:


try
{
// Code that might throw an exception
}
catch (Exception ex)
{
Log(TraceLevel.Error, ex);
}

Implements

Name
Description

Defines a contract for logging services that support logging messages with a specified trace level and optional formatting arguments.

Last updated