Table of Contents

Interface ILogService

Namespace
SharpConsoleUI.Logging
Assembly
SharpConsoleUI.dll

Library-managed logging service that handles all internal logging. Users can subscribe to log events or access the log buffer directly.

public interface ILogService

Properties

Count

Gets the current number of log entries in the buffer

int Count { get; }

Property Value

int

IsEnabled

Gets or sets whether logging is enabled

bool IsEnabled { get; set; }

Property Value

bool

IsFileLoggingEnabled

Gets whether file logging is currently enabled

bool IsFileLoggingEnabled { get; }

Property Value

bool

MaxBufferSize

Gets or sets the maximum number of log entries to retain in the buffer. Default: 1000

int MaxBufferSize { get; set; }

Property Value

int

MinimumLevel

Gets or sets the minimum log level. Messages below this level are ignored. Default: Warning

LogLevel MinimumLevel { get; set; }

Property Value

LogLevel

Methods

ClearLogs()

Clears all log entries from the buffer

void ClearLogs()

DisableFileLogging()

Disables file logging and closes the log file

void DisableFileLogging()

EnableFileLogging(string, bool)

Enables file logging to the specified path. The file will be created if it doesn't exist. Parent directories will be created if needed.

void EnableFileLogging(string filePath, bool append = true)

Parameters

filePath string

Path to the log file

append bool

If true, appends to existing file; if false, overwrites

GetAllLogs()

Gets all log entries currently in the buffer

IReadOnlyList<LogEntry> GetAllLogs()

Returns

IReadOnlyList<LogEntry>

Read-only list of all buffered log entries

GetRecentLogs(int)

Gets the most recent log entries

IReadOnlyList<LogEntry> GetRecentLogs(int count = 100)

Parameters

count int

Maximum number of entries to return

Returns

IReadOnlyList<LogEntry>

Read-only list of log entries, newest first

Log(LogLevel, string, string?)

Logs a message at the specified level

void Log(LogLevel level, string message, string? category = null)

Parameters

level LogLevel

The log level

message string

The message to log

category string

Optional category for grouping

LogCritical(string, Exception?, string?)

Logs a critical error message with optional exception

void LogCritical(string message, Exception? exception = null, string? category = null)

Parameters

message string
exception Exception
category string

LogDebug(string, string?)

Logs a debug message

void LogDebug(string message, string? category = null)

Parameters

message string
category string

LogError(string, Exception?, string?)

Logs an error message with optional exception

void LogError(string message, Exception? exception = null, string? category = null)

Parameters

message string
exception Exception
category string

LogInfo(string, string?)

Logs an informational message

void LogInfo(string message, string? category = null)

Parameters

message string
category string

LogTrace(string, string?)

Logs a trace message (most verbose)

void LogTrace(string message, string? category = null)

Parameters

message string
category string

LogWarning(string, string?)

Logs a warning message

void LogWarning(string message, string? category = null)

Parameters

message string
category string

Events

LogAdded

Raised when a new log entry is added (after passing the minimum level filter)

event EventHandler<LogEntry>? LogAdded

Event Type

EventHandler<LogEntry>

LogsCleared

Raised when the log buffer is cleared

event EventHandler? LogsCleared

Event Type

EventHandler