- rework: Logging logic and file logging
This commit is contained in:
@@ -10,6 +10,7 @@ using Nebula.Launcher.ViewModels.Popup;
|
||||
using Nebula.Launcher.Views;
|
||||
using Nebula.Shared.Models;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.Services.Logging;
|
||||
using Nebula.Shared.Utils;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels;
|
||||
@@ -43,6 +44,8 @@ public partial class MainViewModel : ViewModelBase
|
||||
[GenerateProperty, DesignConstruct] private ViewHelperService ViewHelperService { get; } = default!;
|
||||
[GenerateProperty] private FileService FileService { get; } = default!;
|
||||
|
||||
private ILogger _logger;
|
||||
|
||||
public ObservableCollection<ListItemTemplate> Items { get; private set; }
|
||||
|
||||
protected override void InitialiseInDesignMode()
|
||||
@@ -53,6 +56,7 @@ public partial class MainViewModel : ViewModelBase
|
||||
|
||||
protected override void Initialise()
|
||||
{
|
||||
_logger = DebugService.GetLogger(this);
|
||||
InitialiseInDesignMode();
|
||||
|
||||
PopupMessageService.OnPopupRequired += OnPopupRequired;
|
||||
@@ -160,7 +164,7 @@ public partial class MainViewModel : ViewModelBase
|
||||
break;
|
||||
case Exception error:
|
||||
var err = ViewHelperService.GetViewModel<ExceptionListViewModel>();
|
||||
DebugService.Error(error);
|
||||
_logger.Error(error);
|
||||
err.AppendError(error);
|
||||
PopupMessage(err);
|
||||
break;
|
||||
|
||||
@@ -15,6 +15,7 @@ using Nebula.Launcher.Views.Pages;
|
||||
using Nebula.Shared.FileApis;
|
||||
using Nebula.Shared.Models;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.Services.Logging;
|
||||
using Nebula.Shared.Utils;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels.Pages;
|
||||
@@ -31,6 +32,7 @@ public sealed partial class ContentBrowserViewModel : ViewModelBase , IViewModel
|
||||
[ObservableProperty] private string _searchText = "";
|
||||
|
||||
private ContentEntry? _selectedEntry;
|
||||
private ILogger _logger;
|
||||
[ObservableProperty] private string _serverText = "";
|
||||
[ObservableProperty] private ContentViewBase? _contentView;
|
||||
public bool IsCustomContenView => ContentView != null;
|
||||
@@ -69,7 +71,7 @@ public sealed partial class ContentBrowserViewModel : ViewModelBase , IViewModel
|
||||
var myTempFile = Path.Combine(Path.GetTempPath(), "tempie" + ext);
|
||||
|
||||
if(TryGetContentViewer(ext, out var contentViewBase)){
|
||||
DebugService.Debug($"Opening custom context:{item.Value.Path}");
|
||||
_logger.Debug($"Opening custom context:{item.Value.Path}");
|
||||
contentViewBase.InitialiseWithData(value.GetPath(), stream, value);
|
||||
stream.Dispose();
|
||||
ContentView = contentViewBase;
|
||||
@@ -88,7 +90,7 @@ public sealed partial class ContentBrowserViewModel : ViewModelBase , IViewModel
|
||||
};
|
||||
|
||||
|
||||
DebugService.Log("Opening " + myTempFile);
|
||||
_logger.Log("Opening " + myTempFile);
|
||||
Process.Start(startInfo);
|
||||
|
||||
return;
|
||||
@@ -122,6 +124,7 @@ public sealed partial class ContentBrowserViewModel : ViewModelBase , IViewModel
|
||||
|
||||
protected override void Initialise()
|
||||
{
|
||||
_logger = DebugService.GetLogger(this);
|
||||
FillRoot(HubService.ServerList);
|
||||
|
||||
HubService.HubServerChangedEventArgs += HubServerChangedEventArgs;
|
||||
@@ -173,7 +176,7 @@ public sealed partial class ContentBrowserViewModel : ViewModelBase , IViewModel
|
||||
|
||||
if (ServerText != SelectedEntry?.ServerName) SelectedEntry = await CreateEntry(ServerText);
|
||||
|
||||
DebugService.Debug("Going to:" + path.Path);
|
||||
_logger.Debug("Going to:" + path.Path);
|
||||
|
||||
var oriPath = path.Clone();
|
||||
try
|
||||
@@ -214,7 +217,7 @@ public sealed partial class ContentBrowserViewModel : ViewModelBase , IViewModel
|
||||
FileName = "explorer.exe",
|
||||
Arguments = tmpDir,
|
||||
};
|
||||
DebugService.Log("Opening " + tmpDir);
|
||||
_logger.Log("Opening " + tmpDir);
|
||||
Process.Start(startInfo);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Nebula.Launcher.ViewModels.Pages;
|
||||
using Nebula.Launcher.Views.Pages;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.Services.Logging;
|
||||
using Nebula.Shared.Utils;
|
||||
using AddFavoriteView = Nebula.Launcher.Views.Popup.AddFavoriteView;
|
||||
|
||||
@@ -12,12 +13,15 @@ namespace Nebula.Launcher.ViewModels.Popup;
|
||||
[ConstructGenerator]
|
||||
public partial class AddFavoriteViewModel : PopupViewModelBase
|
||||
{
|
||||
private ILogger _logger;
|
||||
|
||||
protected override void InitialiseInDesignMode()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Initialise()
|
||||
{
|
||||
_logger = DebugService.GetLogger(this);
|
||||
}
|
||||
|
||||
[GenerateProperty]
|
||||
@@ -41,7 +45,7 @@ public partial class AddFavoriteViewModel : PopupViewModelBase
|
||||
catch (Exception e)
|
||||
{
|
||||
Error = e.Message;
|
||||
DebugService.Error(e);
|
||||
_logger.Error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ using Nebula.Launcher.ViewModels.Popup;
|
||||
using Nebula.Launcher.Views;
|
||||
using Nebula.Shared.Models;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.Services.Logging;
|
||||
using Nebula.Shared.Utils;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels;
|
||||
@@ -31,6 +32,8 @@ public partial class ServerEntryModelView : ViewModelBase
|
||||
|
||||
private string _lastError = "";
|
||||
private Process? _p;
|
||||
private ILogger _logger;
|
||||
private ILogger? _processLogger;
|
||||
|
||||
private ServerInfo? _serverInfo;
|
||||
[ObservableProperty] private bool _tagDataVisible;
|
||||
@@ -89,7 +92,7 @@ public partial class ServerEntryModelView : ViewModelBase
|
||||
catch (Exception e)
|
||||
{
|
||||
Description = e.Message;
|
||||
DebugService.Error(e);
|
||||
_logger.Error(e);
|
||||
}
|
||||
|
||||
return _serverInfo;
|
||||
@@ -109,6 +112,7 @@ public partial class ServerEntryModelView : ViewModelBase
|
||||
|
||||
protected override void Initialise()
|
||||
{
|
||||
_logger = DebugService.GetLogger(this);
|
||||
CurrLog = ViewHelperService.GetViewModel<LogPopupModelView>();
|
||||
}
|
||||
|
||||
@@ -144,7 +148,7 @@ public partial class ServerEntryModelView : ViewModelBase
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DebugService.Error(e);
|
||||
_logger.Error(e);
|
||||
Status = new ServerStatus("ErrorLand", $"ERROR: {e.Message}", [], "", -1, -1, -1, false,
|
||||
DateTime.Now,
|
||||
-1);
|
||||
@@ -211,6 +215,8 @@ public partial class ServerEntryModelView : ViewModelBase
|
||||
}
|
||||
|
||||
if (Process is null) return;
|
||||
|
||||
_processLogger = DebugService.GetLogger(buildInfo.BuildInfo.Build.Hash);
|
||||
|
||||
Process.EnableRaisingEvents = true;
|
||||
|
||||
@@ -240,11 +246,13 @@ public partial class ServerEntryModelView : ViewModelBase
|
||||
Process.ErrorDataReceived -= OnErrorDataReceived;
|
||||
Process.Exited -= OnExited;
|
||||
|
||||
DebugService.Log("PROCESS EXIT WITH CODE " + Process.ExitCode);
|
||||
_processLogger?.Log("PROCESS EXIT WITH CODE " + Process.ExitCode);
|
||||
|
||||
if (Process.ExitCode != 0)
|
||||
PopupMessageService.Popup($"Game exit with code {Process.ExitCode}.\nReason: {_lastError}");
|
||||
|
||||
_processLogger?.Dispose();
|
||||
|
||||
Process.Dispose();
|
||||
Process = null;
|
||||
}
|
||||
@@ -254,7 +262,7 @@ public partial class ServerEntryModelView : ViewModelBase
|
||||
if (e.Data != null)
|
||||
{
|
||||
_lastError = e.Data;
|
||||
DebugService.Error(e.Data);
|
||||
_processLogger?.Error(e.Data);
|
||||
CurrLog.Append(e.Data);
|
||||
}
|
||||
}
|
||||
@@ -263,7 +271,7 @@ public partial class ServerEntryModelView : ViewModelBase
|
||||
{
|
||||
if (e.Data != null)
|
||||
{
|
||||
DebugService.Log(e.Data);
|
||||
_processLogger?.Log(e.Data);
|
||||
CurrLog.Append(e.Data);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user