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
IsEnabled
Gets or sets whether logging is enabled
bool IsEnabled { get; set; }
Property Value
IsFileLoggingEnabled
Gets whether file logging is currently enabled
bool IsFileLoggingEnabled { get; }
Property Value
MaxBufferSize
Gets or sets the maximum number of log entries to retain in the buffer. Default: 1000
int MaxBufferSize { get; set; }
Property Value
MinimumLevel
Gets or sets the minimum log level. Messages below this level are ignored. Default: Warning
LogLevel MinimumLevel { get; set; }
Property Value
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
filePathstringPath to the log file
appendboolIf 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
countintMaximum 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
levelLogLevelThe log level
messagestringThe message to log
categorystringOptional 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
LogDebug(string, string?)
Logs a debug message
void LogDebug(string message, string? category = null)
Parameters
LogError(string, Exception?, string?)
Logs an error message with optional exception
void LogError(string message, Exception? exception = null, string? category = null)
Parameters
LogInfo(string, string?)
Logs an informational message
void LogInfo(string message, string? category = null)
Parameters
LogTrace(string, string?)
Logs a trace message (most verbose)
void LogTrace(string message, string? category = null)
Parameters
LogWarning(string, string?)
Logs a warning message
void LogWarning(string message, string? category = null)
Parameters
Events
LogAdded
Raised when a new log entry is added (after passing the minimum level filter)
event EventHandler<LogEntry>? LogAdded
Event Type
LogsCleared
Raised when the log buffer is cleared
event EventHandler? LogsCleared