129 lines
3.9 KiB
Plaintext
129 lines
3.9 KiB
Plaintext
@page "/logs"
|
|
@using BLAIzor.Models
|
|
@inject ApplicationDbContext Db
|
|
@attribute [Authorize]
|
|
|
|
<h3 class="mb-3">📋 Application Logs</h3>
|
|
|
|
<RadzenCard>
|
|
<div class="row g-3">
|
|
<div class="col-md-2">
|
|
<RadzenDropDown @bind-Value="selectedSeverity"
|
|
Data="@severities"
|
|
Placeholder="All Severities"
|
|
AllowClear="true"
|
|
Style="width: 100%;" />
|
|
</div>
|
|
<div class="col-md-3">
|
|
<RadzenDatePicker @bind-Value="startDate" Placeholder="From date" Style="width: 100%;" />
|
|
</div>
|
|
<div class="col-md-3">
|
|
<RadzenDatePicker @bind-Value="endDate" Placeholder="To date" Style="width: 100%;" />
|
|
</div>
|
|
<div class="col-md-2">
|
|
<RadzenButton Text="Search" Click="LoadLogs" Icon="search" Style="width: 100%;" />
|
|
</div>
|
|
</div>
|
|
</RadzenCard>
|
|
|
|
<br />
|
|
|
|
<RadzenDataGrid TItem="AppLog" Data="@logs" Count="@totalCount"
|
|
LoadData="@LoadData" AllowPaging="true" PageSize="10"
|
|
AllowSorting="true" AllowFiltering="false"
|
|
ColumnWidth="200px" ShowPagingSummary="true">
|
|
<Columns>
|
|
<RadzenDataGridColumn Width="100px" TItem="AppLog" Property="Timestamp" Title="Time" FormatString="{0:yyyy-MM-dd HH:mm:ss}" />
|
|
<RadzenDataGridColumn Width="100px" TItem="AppLog" Property="Severity" Title="Severity" />
|
|
<RadzenDataGridColumn TItem="AppLog" Property="Message" Title="Message" />
|
|
<RadzenDataGridColumn TItem="AppLog" Property="Details" Title="Details" />
|
|
</Columns>
|
|
</RadzenDataGrid>
|
|
|
|
<br />
|
|
|
|
<h4>📊 Log Summary</h4>
|
|
|
|
<RadzenStack Style="width: 100%;">
|
|
<RadzenChart SeriesClick=@OnSeriesClick>
|
|
<RadzenPieSeries Data="@logChartData" Title="Logs" CategoryProperty="Severity" ValueProperty="Count">
|
|
<RadzenSeriesDataLabels Visible="true" />
|
|
</RadzenPieSeries>
|
|
</RadzenChart>
|
|
</RadzenStack>
|
|
|
|
|
|
@code {
|
|
private List<AppLog> logs = new();
|
|
private int totalCount = 0;
|
|
|
|
private string? selectedSeverity;
|
|
private DateTime? startDate;
|
|
private DateTime? endDate;
|
|
|
|
private List<string> severities = new() { "Info", "Warning", "Error" };
|
|
|
|
private List<LogChartItem> logChartData = new();
|
|
|
|
void OnSeriesClick(SeriesClickEventArgs args)
|
|
{
|
|
// console.Log(args);
|
|
}
|
|
|
|
private async Task LoadData(LoadDataArgs args)
|
|
{
|
|
var query = Db.Logs.AsQueryable();
|
|
|
|
if (!string.IsNullOrEmpty(selectedSeverity))
|
|
query = query.Where(l => l.Severity == selectedSeverity);
|
|
|
|
if (startDate.HasValue)
|
|
query = query.Where(l => l.Timestamp >= startDate.Value);
|
|
|
|
if (endDate.HasValue)
|
|
query = query.Where(l => l.Timestamp <= endDate.Value);
|
|
|
|
totalCount = query.Count();
|
|
|
|
logs = query
|
|
.OrderByDescending(l => l.Timestamp)
|
|
.Skip(args.Skip ?? 0)
|
|
.Take(args.Top ?? 10).ToList();
|
|
|
|
await LoadChartData();
|
|
}
|
|
|
|
private async Task LoadLogs()
|
|
{
|
|
await LoadData(new LoadDataArgs { Skip = 0, Top = 10 });
|
|
}
|
|
|
|
private async Task LoadChartData()
|
|
{
|
|
var query = Db.Logs.AsQueryable();
|
|
|
|
if (!string.IsNullOrEmpty(selectedSeverity))
|
|
query = query.Where(l => l.Severity == selectedSeverity);
|
|
|
|
if (startDate.HasValue)
|
|
query = query.Where(l => l.Timestamp >= startDate.Value);
|
|
|
|
if (endDate.HasValue)
|
|
query = query.Where(l => l.Timestamp <= endDate.Value);
|
|
|
|
logChartData = query
|
|
.GroupBy(l => l.Severity)
|
|
.Select(g => new LogChartItem
|
|
{
|
|
Severity = g.Key,
|
|
Count = g.Count()
|
|
})
|
|
.ToList();
|
|
}
|
|
|
|
public class LogChartItem
|
|
{
|
|
public string Severity { get; set; } = "";
|
|
public int Count { get; set; }
|
|
}
|
|
} |