日志系统3

This commit is contained in:
2026-02-05 11:20:09 +08:00
parent ba22066a23
commit 66790be755
4 changed files with 42 additions and 61 deletions

View File

@@ -2,14 +2,12 @@ using CosmosFtpServer;
using System;
using System.Collections.Generic;
using System.IO;
using CMLeonOS.Logger;
namespace CMLeonOS
{
public class FileSystem
{
private string currentDirectory;
private static CMLeonOS.Logger.Logger _logger = CMLeonOS.Logger.Logger.Instance;
public FileSystem()
{
@@ -26,9 +24,9 @@ namespace CMLeonOS
if (string.IsNullOrEmpty(path))
{
currentDirectory = @"0:\";
_logger.Info("FileSystem", "Changed to root directory");
return;
}
string fullPath = GetFullPath(path);
try
@@ -36,16 +34,15 @@ namespace CMLeonOS
if (Directory.Exists(fullPath))
{
currentDirectory = fullPath;
_logger.Info("FileSystem", $"Changed directory to: {path}");
}
else
{
_logger.Warning("FileSystem", $"Directory not found: {path}");
Console.WriteLine($"Directory not found: {path}");
}
}
catch (Exception ex)
{
_logger.Error("FileSystem", $"Error changing directory: {ex.Message}");
Console.WriteLine($"Error changing directory: {ex.Message}");
}
}
@@ -58,16 +55,16 @@ namespace CMLeonOS
if (!Directory.Exists(fullPath))
{
Directory.CreateDirectory(fullPath);
_logger.Info("FileSystem", $"Directory created: {path}");
Console.WriteLine($"Directory created: {path}");
}
else
{
_logger.Warning("FileSystem", $"Directory already exists: {path}");
Console.WriteLine($"Directory already exists: {path}");
}
}
catch (Exception ex)
{
_logger.Error("FileSystem", $"Error creating directory: {ex.Message}");
Console.WriteLine($"Error creating directory: {ex.Message}");
}
}
@@ -233,11 +230,11 @@ namespace CMLeonOS
{
// 创建或覆盖文件
File.WriteAllText(fullPath, content);
_logger.Info("FileSystem", $"File created: {path}");
Console.WriteLine($"File created: {path}");
}
catch (Exception ex)
{
_logger.Error("FileSystem", $"Error creating file: {ex.Message}");
Console.WriteLine($"Error creating file: {ex.Message}");
}
}
@@ -250,16 +247,16 @@ namespace CMLeonOS
if (File.Exists(fullPath))
{
File.WriteAllText(fullPath, content);
_logger.Info("FileSystem", $"File written: {path}");
Console.WriteLine($"File written: {path}");
}
else
{
_logger.Warning("FileSystem", $"File not found: {path}");
Console.WriteLine($"File not found: {path}");
}
}
catch (Exception ex)
{
_logger.Error("FileSystem", $"Error writing file: {ex.Message}");
Console.WriteLine($"Error writing file: {ex.Message}");
}
}