API Reference | Logging

This section of documentation describes the logging system in the OutfitTool API, including the ILogger interface and auxiliary classes LogEntry and LogLevel.

ILogger Interface

The ILogger interface provides methods for logging messages of various importance levels. A logger instance is passed to the module through the Init method of the IModuleController interface.

Interface Definition

namespace OutfitTool.API1.Logger;

public interface ILogger
{
    void Debug(string log);
    void Info(string log);
    void Error(string log);
    void Warning(string log);
    void Critical(string log);
    void Status(string log);
}

Interface Methods

void Debug(string log)
Writes a debug message. Used for detailed logging of internal module processes during development and debugging.
void Info(string log)
Writes an informational message. Used to register important events in module operation (e.g., successful initialization, data loading).
void Error(string log)
Writes an error message. Used when errors occur that do not lead to a critical module failure.
void Warning(string log)
Writes a warning. Used when potentially undesirable situations arise (e.g., outdated settings, temporary resource unavailability).
void Critical(string log)
Writes a critical message. Used when fatal errors occur that may lead to module malfunction.
void Status(string log)
Writes a message that is displayed in the status bar of the main program window. Used to inform the user about the current state of the module.

LogLevel Enumeration

The LogLevel enumeration defines the importance levels of log messages. Used by the LogEntry class to specify the message level.

Enumeration Definition

namespace OutfitTool.API1.Logger;

public enum LogLevel
{
    Debug, 
    Info, 
    Error, 
    Warning, 
    Critical,
    Status
}

Enumeration Values

  • Debug - debug message
  • Info - informational message
  • Error - error message
  • Warning - warning
  • Critical - critical message
  • Status - status bar message

LogEntry Class

The LogEntry class represents a log entry containing information about the message, its level, and timestamp. Inherits from EventArgs, allowing it to be used in events.

Class Definition

namespace OutfitTool.API1.Logger;

public class LogEntry(LogLevel level, string message) : EventArgs
{
    public LogLevel Level = level;
    public string Message = message;
    public DateTime LogDateTime = DateTime.Now;
}

Class Properties

LogLevel Level
Message importance level defined by the LogLevel enumeration.
string Message
Text of the message recorded in the log.
DateTime LogDateTime
Date and time of the message recording in the log. Set automatically when creating a class instance.

Usage Example

The logger is used in the module as follows:

private ILogger? _logger;

public void Init(ILogger logger)
{
    _logger = logger;
    
    // Writing an informational message
    _logger.Info("Module successfully initialized");
    
    // Writing a debug message
    _logger.Debug("Current module version: 1.0.0");
}

public void SomeMethod()
{
    try
    {
        // Some operation
        DoSomething();
        
        // Successful execution
        _logger?.Info("Operation completed successfully");
    }
    catch (Exception ex)
    {
        // Writing an error
        _logger?.Error($"Error during operation execution: {ex.Message}");
    }
}

Usage Recommendations

  • Use the appropriate logging level for each type of message
  • Save the logger instance during module initialization for subsequent use
  • Use logging for debugging and monitoring module operation
  • Do not log sensitive information (passwords, tokens, etc.)
  • Use the Status method to inform the user about the current state of the module