@page "/" @using DiscordBotCore.Bot @using DiscordBotCore.PluginManagement.Loading @using WebUI.Models @using WebUI.Services @inject IDiscordBotApplication DiscordBotApplication @inject IPluginLoader PluginLoader @inject DiscordBotCore.Logging.ILogger Logger @inject IJSRuntime JS @inject NotificationService NotificationService @rendermode InteractiveServer

Console Log Viewer

Console Log

@foreach (var line in Logs) {
@line
}

Controls

@code { private bool IsRunning { get; set; } private List Logs { get; set; } = new(); private Timer? _logTimer; private int _lastLogCount = 0; private readonly object _logLock = new(); protected override void OnInitialized() { IsRunning = DiscordBotApplication.IsReady; _logTimer = new Timer(async _ => await RefreshLogsAsync(), null, 0, 2000); } private async Task StartApplication() { if (!DiscordBotApplication.IsReady) { await DiscordBotApplication.StartAsync(); Logger.Log("Application started", this); } IsRunning = DiscordBotApplication.IsReady; } private async Task StopApplication() { if (DiscordBotApplication.IsReady) { await DiscordBotApplication.StopAsync(); Logger.Log("Application stopped", this); } IsRunning = DiscordBotApplication.IsReady; } private async Task LoadPlugins() { Logger.Log("Loading plugins", this); await PluginLoader.LoadPlugins(); Logger.Log("Plugins loaded", this); NotificationService.Notify("Plugins Loaded !", NotificationType.Success); } private string GetLogStyle(string line) { if (line.Contains("[Error]")) return "color: #ff4d4d;"; if (line.Contains("[Warning]")) return "color: #ffa500;"; if (line.Contains("[Debug]")) return "color: #88f;"; return ""; } private async Task RefreshLogsAsync() { try { var logText = Logger.GetLogsHistory(); var newLogs = logText.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); if (newLogs.Length != _lastLogCount) { lock (_logLock) { Logs = newLogs.ToList(); _lastLogCount = newLogs.Length; } await InvokeAsync(async () => { StateHasChanged(); await JS.InvokeVoidAsync("scrollToBottom", "consoleLog"); }); } } catch (Exception ex) { } } public void Dispose() { _logTimer?.Dispose(); } }