@page "/logs" @using Microsoft.EntityFrameworkCore @using TrafagSalesExporter.Data @inject IDbContextFactory DbFactory @inject ISnackbar Snackbar @inject IDialogService DialogService @inject TrafagSalesExporter.Services.IUiTextService UiText @T("Logs", "Logs") @T("Export Logs", "Export Logs") @foreach (var land in _availableLands) { @land } OK Error @T("Filtern", "Filter") @T("Alte Logs loeschen", "Delete old logs") @T("Zeitpunkt", "Timestamp") @T("Land", "Country") TSC @T("Status", "Status") @T("Zeilen", "Rows") @T("Dauer", "Duration") @T("Dateiname", "File name") @T("Fehler", "Error") @context.Timestamp.ToString("dd.MM.yyyy HH:mm:ss") @context.Land @context.TSC @if (context.Status == "OK") { OK } else { Error } @context.RowCount.ToString("N0") @($"{context.DurationSeconds:F1}s") @context.FileName @if (!string.IsNullOrEmpty(context.ErrorMessage)) { @context.ErrorMessage } @T("Technische Logs", "Technical logs") @T("Zeitpunkt", "Timestamp") Level @T("Kategorie", "Category") @T("Land", "Country") @T("Meldung", "Message") Details @context.Timestamp.ToString("dd.MM.yyyy HH:mm:ss") @context.Level @context.Category @(string.IsNullOrWhiteSpace(context.Land) ? "-" : context.Land) @context.Message @if (!string.IsNullOrWhiteSpace(context.Details)) { @context.Details } @code { private List _logs = new(); private List _appLogs = new(); private List _availableLands = new(); private string? _filterLand; private string? _filterStatus; private DateTime? _filterDate; private bool _loading = true; protected override async Task OnInitializedAsync() { using var db = await DbFactory.CreateDbContextAsync(); _availableLands = await db.ExportLogs.Select(l => l.Land).Distinct().OrderBy(l => l).ToListAsync(); await LoadLogsAsync(); } private async Task LoadLogsAsync() { _loading = true; using var db = await DbFactory.CreateDbContextAsync(); IQueryable query = db.ExportLogs.OrderByDescending(l => l.Timestamp); if (!string.IsNullOrEmpty(_filterLand)) query = query.Where(l => l.Land == _filterLand); if (!string.IsNullOrEmpty(_filterStatus)) query = query.Where(l => l.Status == _filterStatus); if (_filterDate.HasValue) query = query.Where(l => l.Timestamp.Date == _filterDate.Value.Date); _logs = await query.Take(500).ToListAsync(); IQueryable appLogQuery = db.AppEventLogs.OrderByDescending(l => l.Timestamp); if (!string.IsNullOrEmpty(_filterLand)) appLogQuery = appLogQuery.Where(l => l.Land == _filterLand); if (_filterDate.HasValue) appLogQuery = appLogQuery.Where(l => l.Timestamp.Date == _filterDate.Value.Date); _appLogs = await appLogQuery.Take(500).ToListAsync(); _loading = false; } private async Task ApplyFilter() { await LoadLogsAsync(); } private async Task DeleteOldLogs() { var result = await DialogService.ShowMessageBox( T("Alte Logs loeschen", "Delete old logs"), T("Logs aelter als 90 Tage loeschen?", "Delete logs older than 90 days?"), yesText: T("Loeschen", "Delete"), cancelText: T("Abbrechen", "Cancel")); if (result != true) return; using var db = await DbFactory.CreateDbContextAsync(); var cutoff = DateTime.Now.AddDays(-90); var oldLogs = await db.ExportLogs.Where(l => l.Timestamp < cutoff).ToListAsync(); db.ExportLogs.RemoveRange(oldLogs); var count = await db.SaveChangesAsync(); await LoadLogsAsync(); Snackbar.Add(string.Format(T("{0} alte Logs geloescht", "{0} old logs deleted"), oldLogs.Count), Severity.Info); } } @code { private string T(string german, string english) => UiText.Text(german, english); }