Added: - New `ProgressService` class for managing progress indicators. - New `AssetDatabase`, `AssetOpenHandlerAttribute`, and `AsyncAssetOpenHandlerAttribute` classes for asset handling. - `Ghost.UnitTest` project for unit testing with associated files and configurations. Changed: - `ActivationHandler` class to ensure correct handling of `LaunchActivatedEventArgs`. - `App.xaml.cs` to register `INotificationService` and `IProgressService`, replacing `StackedNotificationService`. - `OnLaunched` method in `App.xaml.cs` to correctly call `ActivationHandler.Handle(args)` and start the host. - `INavigationAware` interface from internal to public for broader access. - `EditorState.cs` to activate `EditorApplication` with the current service provider. - Property names in `AssetItem` and `ExplorerItem` structs to `Name` and `FullName`. - `NotificationService` class to implement `INotificationService` and refactor notification handling. - `AssetPathToGlyphConverter` to handle file extensions consistently. - Bindings in `ProjectPage.xaml` and `ProjectPage.xaml.cs` to use `FullName` instead of `Path`. - `EngineEditorWindow` and `LandingWindow` classes to utilize new notification and progress services. - `Logger` class to include a new method for logging errors with exceptions. Updated: - Manifest files and project files to reflect new structure and dependencies. - Solution file `GhostEngine.sln` to include the new unit test project. - Added several new test classes and methods in `UnitTests.cs`.
92 lines
2.1 KiB
C#
92 lines
2.1 KiB
C#
using Ghost.Engine.Models;
|
|
using System.Diagnostics;
|
|
|
|
namespace Ghost.Engine.Services;
|
|
|
|
internal enum LogChangeType
|
|
{
|
|
LogAdded,
|
|
LogRemoved,
|
|
LogsCleared
|
|
}
|
|
|
|
public static class Logger
|
|
{
|
|
|
|
private const int _MAX_LOGS = 4096;
|
|
|
|
private static readonly List<LogMessage> _logs = new();
|
|
internal static IReadOnlyList<LogMessage> Logs => _logs;
|
|
|
|
internal static event Action<LogChangeType>? OnLogsUpdate;
|
|
|
|
internal static bool HasStackTrace
|
|
{
|
|
get; set;
|
|
}
|
|
|
|
private static void LogInternal(LogLevel level, string message, int skipFrame)
|
|
{
|
|
if (_logs.Count >= _MAX_LOGS)
|
|
{
|
|
_logs.RemoveAt(0);
|
|
OnLogsUpdate?.Invoke(LogChangeType.LogRemoved);
|
|
}
|
|
|
|
StackTrace? stackTrace = null;
|
|
if (HasStackTrace)
|
|
{
|
|
stackTrace = new StackTrace(skipFrame, true);
|
|
}
|
|
|
|
var logMessage = new LogMessage(level, message, stackTrace?.ToString());
|
|
_logs.Add(logMessage);
|
|
|
|
OnLogsUpdate?.Invoke(LogChangeType.LogAdded);
|
|
}
|
|
|
|
private static void LogExceptionInternal(Exception ex)
|
|
{
|
|
if (_logs.Count >= _MAX_LOGS)
|
|
{
|
|
_logs.RemoveAt(0);
|
|
OnLogsUpdate?.Invoke(LogChangeType.LogRemoved);
|
|
}
|
|
|
|
var logMessage = new LogMessage(LogLevel.Error, ex.Message, ex.StackTrace);
|
|
_logs.Add(logMessage);
|
|
|
|
OnLogsUpdate?.Invoke(LogChangeType.LogAdded);
|
|
}
|
|
|
|
public static void Log(LogLevel level, string message)
|
|
{
|
|
LogInternal(level, message, 2);
|
|
}
|
|
|
|
public static void LogInfo(string message)
|
|
{
|
|
LogInternal(LogLevel.Info, message, 3);
|
|
}
|
|
|
|
public static void LogWarning(string message)
|
|
{
|
|
LogInternal(LogLevel.Warning, message, 3);
|
|
}
|
|
|
|
public static void LogError(string message)
|
|
{
|
|
LogInternal(LogLevel.Error, message, 3);
|
|
}
|
|
|
|
public static void LogError(Exception ex)
|
|
{
|
|
LogExceptionInternal(ex);
|
|
}
|
|
|
|
internal static void Clear()
|
|
{
|
|
_logs.Clear();
|
|
OnLogsUpdate?.Invoke(LogChangeType.LogsCleared);
|
|
}
|
|
} |