Initial commit - Pingerino network monitoring application

هذا الالتزام موجود في:
Era
2025-08-19 07:34:27 +03:00
التزام 243f4787dd
41 ملفات معدلة مع 12352 إضافات و0 حذوفات

عرض الملف

@@ -0,0 +1,59 @@
using System;
using System.IO;
using Pingerino.Services.Interfaces;
namespace Pingerino.Services
{
public class LoggingService : ILoggingService
{
private readonly string _logFilePath;
private readonly object _lockObject = new object();
public LoggingService()
{
var logDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Pingerino", "Logs");
Directory.CreateDirectory(logDirectory);
_logFilePath = Path.Combine(logDirectory, $"pingerino_{DateTime.Now:yyyyMMdd}.log");
}
public void LogInformation(string message)
{
WriteLog(LogLevel.Information, message);
}
public void LogWarning(string message)
{
WriteLog(LogLevel.Warning, message);
}
public void LogError(string message, Exception exception = null)
{
var fullMessage = exception != null ? $"{message} - Exception: {exception}" : message;
WriteLog(LogLevel.Error, fullMessage);
}
public void LogDebug(string message)
{
WriteLog(LogLevel.Debug, message);
}
private void WriteLog(LogLevel level, string message)
{
try
{
lock (_lockObject)
{
var logEntry = $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}] [{level}] {message}";
File.AppendAllText(_logFilePath, logEntry + Environment.NewLine);
// Also write to console for debugging
Console.WriteLine(logEntry);
}
}
catch
{
// Ignore logging errors to prevent infinite loops
}
}
}
}