using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DataPoolingService { class Logger { // Get the desktop folder path static string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); // Create a log file path static string logFilePath = Path.Combine(desktopPath, "ScadaLog.txt"); DateTime currentDate = DateTime.Now; public void StartLogEvent() { bool fileExists = File.Exists(logFilePath); using (StreamWriter writer = new StreamWriter(logFilePath, fileExists)) { writer.WriteLine($"Logging process started at: {currentDate}"); } } public void EndLogEvent() { // Check if the log file exists bool fileExists = File.Exists(logFilePath); using (StreamWriter writer = new StreamWriter(logFilePath, fileExists)) { writer.WriteLine($"Logging process ended at: {DateTime.Now}"); } } public void RowSuccessLog(string meter_no,int site_id , double units) { // Check if the log file exists bool fileExists = File.Exists(logFilePath); using (StreamWriter writer = new StreamWriter(logFilePath, fileExists)) { writer.WriteLine($"Row inserted successfully - Meter No: {meter_no}, Site ID: {site_id}, Units: {units}"); } } public void RowFailedLog(string meter_no, int site_id, double units) { // Check if the log file exists bool fileExists = File.Exists(logFilePath); using (StreamWriter writer = new StreamWriter(logFilePath, fileExists)) { writer.WriteLine($"Row insertion failed - Meter No: {meter_no}, Site ID: {site_id}, Units: {units}"); } } public void RowAlreadyExistsLog(string meter_no, int site_id, double units) { // Check if the log file exists bool fileExists = File.Exists(logFilePath); using (StreamWriter writer = new StreamWriter(logFilePath, fileExists)) { writer.WriteLine($"Row already exists - Meter No: {meter_no}, Site ID: {site_id}, Units: {units}"); } } public void RecordExistLog() { bool fileExists = File.Exists(logFilePath); using (StreamWriter writer = new StreamWriter(logFilePath, fileExists)) { // Check if the log file exists writer.WriteLine($"Record already exist ------ Date: {DateTime.Now} "); } } public void NotFoundLog() { bool fileExists = File.Exists(logFilePath); using (StreamWriter writer = new StreamWriter(logFilePath, fileExists)) { // Check if the log file exists writer.WriteLine($"Record not found ------ Date: {DateTime.Now} "); } } } }