/* * ThreadPilot - Advanced Windows Process and Power Plan Manager * Copyright (C) 2025 Prime Build * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, version 3 only. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ namespace ThreadPilot.Services { using System; using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.Extensions.Logging; /// /// Enhanced logging service interface for persistent, structured logging. /// public interface IEnhancedLoggingService { /// /// Gets the current log file path. /// string CurrentLogFilePath { get; } /// /// Gets the log directory path. /// string LogDirectoryPath { get; } /// /// Gets a value indicating whether gets whether debug logging is enabled. /// bool IsDebugLoggingEnabled { get; } /// /// Event raised when a critical error occurs /// event EventHandler? CriticalErrorOccurred; /// /// Initialize the logging service. /// Task InitializeAsync(); /// /// Log a power plan change event. /// Task LogPowerPlanChangeAsync(string fromPlan, string toPlan, string reason, string? processName = null); /// /// Log a process monitoring event. /// Task LogProcessMonitoringEventAsync(string eventType, string processName, int processId, string details); /// /// Log a user action. /// Task LogUserActionAsync(string action, string details, string? context = null); /// /// Log a system event. /// Task LogSystemEventAsync(string eventType, string message, LogLevel level = LogLevel.Information); /// /// Log an error with structured data. /// Task LogErrorAsync(Exception exception, string context, Dictionary? additionalData = null); /// /// Log application startup/shutdown events. /// Task LogApplicationLifecycleEventAsync(string eventType, string details); /// /// Get recent log entries. /// Task> GetRecentLogEntriesAsync(int count = 100); /// /// Begin a correlated operation scope for better debugging. /// IDisposable BeginScope(string operationName, object? parameters = null); /// /// Get the current correlation ID. /// string? GetCurrentCorrelationId(); /// /// Get log entries for a specific date range. /// Task> GetLogEntriesAsync(DateTime fromDate, DateTime toDate); /// /// Clean up old log files based on retention policy. /// Task CleanupOldLogsAsync(); /// /// Get log file statistics. /// Task GetLogStatisticsAsync(); /// /// Export logs to a file. /// Task ExportLogsAsync(DateTime fromDate, DateTime toDate, string? exportPath = null); /// /// Update logging configuration. /// Task UpdateConfigurationAsync(bool enableDebugLogging, int maxFileSizeMb, int retentionDays); } /// /// Event args for critical errors. /// public class CriticalErrorEventArgs : EventArgs { public Exception Exception { get; } public string Context { get; } public DateTime Timestamp { get; } public Dictionary AdditionalData { get; } public CriticalErrorEventArgs(Exception exception, string context, Dictionary? additionalData = null) { this.Exception = exception; this.Context = context; this.Timestamp = DateTime.UtcNow; this.AdditionalData = additionalData ?? new Dictionary(); } } /// /// Represents a log entry. /// public class LogEntry { public DateTime Timestamp { get; set; } public LogLevel Level { get; set; } public string Category { get; set; } = string.Empty; public string Message { get; set; } = string.Empty; public string? Exception { get; set; } public Dictionary Properties { get; set; } = new(); public string? CorrelationId { get; set; } } /// /// Log file statistics. /// public class LogFileStatistics { public long CurrentFileSizeBytes { get; set; } public int TotalLogFiles { get; set; } public long TotalLogSizeBytes { get; set; } public DateTime OldestLogDate { get; set; } public DateTime NewestLogDate { get; set; } public int ErrorCount { get; set; } public int WarningCount { get; set; } public int InfoCount { get; set; } } }