96 lines
3 KiB
Text
96 lines
3 KiB
Text
@page "/logs"
|
|
@attribute [Authorize]
|
|
@rendermode InteractiveServer
|
|
@inject LogService LogService
|
|
@inject IJSRuntime JSRuntime
|
|
|
|
<PageTitle>Logs</PageTitle>
|
|
|
|
<h1>System-Logs</h1>
|
|
|
|
<div class="row mb-3">
|
|
<div class="col-md-4">
|
|
<label class="form-label">Log-Datei</label>
|
|
<select class="form-select" @bind="_selectedFileName" @bind:after="LoadSelectedLog">
|
|
@if (_logFiles.Count == 0)
|
|
{
|
|
<option value="">Keine Logs vorhanden</option>
|
|
}
|
|
else
|
|
{
|
|
@foreach (var file in _logFiles)
|
|
{
|
|
<option value="@Path.GetFileName(file)">@Path.GetFileName(file)</option>
|
|
}
|
|
}
|
|
</select>
|
|
</div>
|
|
<div class="col-md-2">
|
|
<label class="form-label">Zeilen</label>
|
|
<select class="form-select" @bind="_maxLines" @bind:after="LoadSelectedLog">
|
|
<option value="100">100</option>
|
|
<option value="500">500</option>
|
|
<option value="1000">1000</option>
|
|
<option value="5000">5000</option>
|
|
</select>
|
|
</div>
|
|
<div class="col-md-6 d-flex align-items-end">
|
|
<button class="btn btn-outline-secondary me-2" @onclick="LoadSelectedLog">Aktualisieren</button>
|
|
<button class="btn btn-outline-primary" @onclick="DownloadLog">Herunterladen</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="card-header d-flex justify-content-between align-items-center">
|
|
<span>Log-Ausgabe</span>
|
|
<span class="badge bg-secondary">@_logContent.Split('\n').Length Zeilen</span>
|
|
</div>
|
|
<div class="card-body p-0">
|
|
<pre class="m-0 p-3 bg-dark text-light" style="max-height: 70vh; overflow: auto; font-size: 0.85rem;"><code>@_logContent</code></pre>
|
|
</div>
|
|
</div>
|
|
|
|
@code {
|
|
private List<string> _logFiles = new();
|
|
private string _selectedFileName = "";
|
|
private int _maxLines = 1000;
|
|
private string _logContent = "Keine Log-Datei ausgewählt.";
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
LoadLogFiles();
|
|
}
|
|
|
|
private void LoadLogFiles()
|
|
{
|
|
_logFiles = LogService.GetLogFiles();
|
|
if (_logFiles.Any() && string.IsNullOrEmpty(_selectedFileName))
|
|
{
|
|
_selectedFileName = Path.GetFileName(_logFiles.First());
|
|
LoadSelectedLog();
|
|
}
|
|
}
|
|
|
|
private void LoadSelectedLog()
|
|
{
|
|
if (string.IsNullOrEmpty(_selectedFileName))
|
|
{
|
|
_logContent = "Keine Log-Datei ausgewählt.";
|
|
return;
|
|
}
|
|
|
|
_logContent = LogService.ReadLogFile(_selectedFileName, _maxLines);
|
|
}
|
|
|
|
private async Task DownloadLog()
|
|
{
|
|
if (string.IsNullOrEmpty(_selectedFileName))
|
|
return;
|
|
|
|
var content = LogService.ReadLogFile(_selectedFileName, int.MaxValue);
|
|
var bytes = System.Text.Encoding.UTF8.GetBytes(content);
|
|
var base64 = Convert.ToBase64String(bytes);
|
|
|
|
await JSRuntime.InvokeVoidAsync("downloadFileFromBase64", _selectedFileName, base64, "text/plain");
|
|
}
|
|
}
|