ILoggerService

Wisej.AI.Services.ILoggerService

Namespace: Wisej.AI.Services

Assembly: Wisej.AI (3.5.0.0)

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

public interface ILoggerService

Implementations of this interface should provide a mechanism for logging messages that include a specified TraceLevel and a message string. The message can include formatting placeholders that are replaced by the provided arguments. This interface is typically used in applications that require logging capabilities to track the flow of execution and capture debugging information.

Methods

Log(level, context, message, arguments)

Logs a message with a specified trace level and optional formatting arguments.

Parameter
Type
Description

level

The TraceLevel indicating the severity of the log message.

context

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

message

The message to log. This may contain format placeholders.

arguments

Optional. An array of objects to format into the message. Default is an empty array.

This method allows the caller to log a message at a specified trace level. The message may include placeholders that will be replaced by the provided arguments. Example usage:


  ILoggerService logger = new ConsoleLoggerService();
  logger.Log(TraceLevel.Info, "User {0} has logged in at {1}.", "JohnDoe", DateTime.Now);

The method should handle any necessary formatting of the message string with the arguments provided and then record the log entry with the appropriate trace level.

Log(level, context, exception)

Logs an exception with a specified trace level.

Parameter
Type
Description

level

The TraceLevel indicating the severity of the log message.

context

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

exception

The exception to be logged, which provides the message and stack trace.

This method is designed to log exceptions at a specified trace level, capturing the exception's message and stack trace. Example usage:


try
{
// Some code that might throw an exception
}
catch (Exception ex)
{
ILoggerService logger = Application.Services.GetService<ILoggerService>();
logger.Log(TraceLevel.Error, ex);
}

This method simplifies the process of logging exceptions by automatically including essential details such as the exception message and stack trace.

Implemented By

Name
Description

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

Last updated