240 lines
11 KiB
Plaintext
240 lines
11 KiB
Plaintext
@model PowderCoating.Web.Controllers.LogViewerModel
|
|
@{
|
|
ViewData["Title"] = "Log Viewer";
|
|
ViewData["PageIcon"] = "bi-file-text";
|
|
}
|
|
|
|
<div class="container-fluid mt-4">
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<div class="d-flex justify-content-end mb-3">
|
|
<a asp-action="Index" class="btn btn-secondary">
|
|
<i class="bi bi-arrow-left"></i> Back to Diagnostics
|
|
</a>
|
|
</div>
|
|
|
|
@if (TempData["SuccessMessage"] != null)
|
|
{
|
|
<div class="alert alert-success alert-dismissible fade show">
|
|
<i class="bi bi-check-circle"></i> @TempData["SuccessMessage"]
|
|
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
|
|
</div>
|
|
}
|
|
|
|
@if (TempData["ErrorMessage"] != null)
|
|
{
|
|
<div class="alert alert-danger alert-dismissible fade show">
|
|
<i class="bi bi-exclamation-triangle"></i> @TempData["ErrorMessage"]
|
|
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
|
|
</div>
|
|
}
|
|
|
|
@if (!string.IsNullOrEmpty(Model.Error))
|
|
{
|
|
<div class="alert alert-danger">
|
|
<i class="bi bi-exclamation-triangle"></i> @Model.Error
|
|
</div>
|
|
}
|
|
</div>
|
|
</div>
|
|
|
|
@if (Model.AvailableLogFiles.Any())
|
|
{
|
|
<div class="row mb-3">
|
|
<div class="col-12">
|
|
<div class="card">
|
|
<div class="card-header bg-primary text-white">
|
|
<h5 class="mb-0"><i class="bi bi-funnel"></i> Filter & Options</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<form method="get" asp-action="ViewLogs" id="filterForm">
|
|
<div class="row g-3">
|
|
<div class="col-md-4">
|
|
<label for="fileName" class="form-label">Log File</label>
|
|
<select name="fileName" id="fileName" class="form-select" onchange="document.getElementById('filterForm').submit()">
|
|
@foreach (var file in Model.AvailableLogFiles)
|
|
{
|
|
<option value="@file.Name" selected="@(file.Name == Model.SelectedFileName)">
|
|
@file.Name (@((file.Size / 1024.0).ToString("N0")) KB)
|
|
</option>
|
|
}
|
|
</select>
|
|
</div>
|
|
|
|
<div class="col-md-3">
|
|
<label for="lines" class="form-label">Lines to Show</label>
|
|
<select name="lines" id="lines" class="form-select">
|
|
<option value="100" selected="@(Model.SelectedLines == 100)">Last 100</option>
|
|
<option value="500" selected="@(Model.SelectedLines == 500)">Last 500</option>
|
|
<option value="1000" selected="@(Model.SelectedLines == 1000)">Last 1000</option>
|
|
<option value="5000" selected="@(Model.SelectedLines == 5000)">Last 5000</option>
|
|
<option value="999999" selected="@(Model.SelectedLines >= 999999)">All</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="col-md-3">
|
|
<label for="search" class="form-label">Search</label>
|
|
<input type="text" name="search" id="search" class="form-control"
|
|
placeholder="Filter log entries..." value="@Model.SearchTerm">
|
|
</div>
|
|
|
|
<div class="col-md-2">
|
|
<label class="form-label"> </label>
|
|
<button type="submit" class="btn btn-primary w-100">
|
|
<i class="bi bi-search"></i> Apply
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
@if (!string.IsNullOrEmpty(Model.SelectedFileName))
|
|
{
|
|
<div class="row mb-3">
|
|
<div class="col-12">
|
|
<div class="card">
|
|
<div class="card-header bg-secondary text-white d-flex justify-content-between align-items-center">
|
|
<div>
|
|
<h5 class="mb-0">
|
|
<i class="bi bi-file-earmark-text"></i> @Model.SelectedFileName
|
|
</h5>
|
|
<small>
|
|
Showing @Model.DisplayedLines of @Model.TotalLines lines
|
|
@if (!string.IsNullOrWhiteSpace(Model.SearchTerm))
|
|
{
|
|
<span>(@Model.FilteredLines matches for "@Model.SearchTerm")</span>
|
|
}
|
|
</small>
|
|
</div>
|
|
<div>
|
|
<a asp-action="DownloadLog" asp-route-fileName="@Model.SelectedFileName"
|
|
class="btn btn-sm btn-light">
|
|
<i class="bi bi-download"></i> Download
|
|
</a>
|
|
<button type="button" class="btn btn-sm btn-light" onclick="refreshLogs()">
|
|
<i class="bi bi-arrow-clockwise"></i> Refresh
|
|
</button>
|
|
</div>
|
|
</div>
|
|
<div class="card-body p-0">
|
|
<div class="log-content-wrapper">
|
|
<pre class="log-content mb-0" id="logContent">@Model.LogContent</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<div class="card">
|
|
<div class="card-header bg-warning">
|
|
<h6 class="mb-0"><i class="bi bi-gear"></i> Log Management</h6>
|
|
</div>
|
|
<div class="card-body">
|
|
<p>Delete old log files to free up disk space. This will permanently remove log files.</p>
|
|
<form method="post" asp-action="ClearOldLogs" onsubmit="return confirm('Are you sure you want to delete old log files?');">
|
|
<div class="row g-3 align-items-end">
|
|
<div class="col-md-3">
|
|
<label for="daysToKeep" class="form-label">Keep logs from last</label>
|
|
<select name="daysToKeep" id="daysToKeep" class="form-select">
|
|
<option value="7">7 days</option>
|
|
<option value="14">14 days</option>
|
|
<option value="30" selected>30 days</option>
|
|
<option value="60">60 days</option>
|
|
<option value="90">90 days</option>
|
|
</select>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<button type="submit" class="btn btn-warning">
|
|
<i class="bi bi-trash"></i> Clear Old Logs
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
}
|
|
}
|
|
else
|
|
{
|
|
<div class="alert alert-info">
|
|
<i class="bi bi-info-circle"></i> No log files found in <code>@Model.LogsPath</code>
|
|
</div>
|
|
}
|
|
</div>
|
|
|
|
<style>
|
|
.log-content-wrapper {
|
|
max-height: 600px;
|
|
overflow-y: auto;
|
|
background-color: #1e1e1e;
|
|
color: #d4d4d4;
|
|
}
|
|
|
|
.log-content {
|
|
padding: 15px;
|
|
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
|
font-size: 13px;
|
|
line-height: 1.5;
|
|
white-space: pre-wrap;
|
|
word-wrap: break-word;
|
|
}
|
|
|
|
/* Color code log levels */
|
|
.log-content {
|
|
color: #d4d4d4;
|
|
}
|
|
|
|
pre:has(text) {
|
|
background-color: #1e1e1e;
|
|
}
|
|
</style>
|
|
|
|
<script>
|
|
function refreshLogs() {
|
|
location.reload();
|
|
}
|
|
|
|
// Auto-scroll to bottom of logs
|
|
window.addEventListener('load', function() {
|
|
var logContent = document.querySelector('.log-content-wrapper');
|
|
if (logContent) {
|
|
logContent.scrollTop = logContent.scrollHeight;
|
|
}
|
|
});
|
|
|
|
// Highlight search terms
|
|
@if (!string.IsNullOrWhiteSpace(Model.SearchTerm))
|
|
{
|
|
<text>
|
|
window.addEventListener('load', function() {
|
|
var content = document.getElementById('logContent');
|
|
if (content) {
|
|
var searchTerm = '@Html.Raw(System.Web.HttpUtility.JavaScriptStringEncode(Model.SearchTerm))';
|
|
var regex = new RegExp('(' + searchTerm.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + ')', 'gi');
|
|
content.innerHTML = content.textContent.replace(regex, '<mark>$1</mark>');
|
|
}
|
|
});
|
|
</text>
|
|
}
|
|
|
|
// Color code log levels
|
|
window.addEventListener('load', function() {
|
|
var content = document.getElementById('logContent');
|
|
if (content) {
|
|
var html = content.textContent;
|
|
html = html.replace(/\[ERR\]/g, '<span style="color: #f48771; font-weight: bold;">[ERR]</span>');
|
|
html = html.replace(/\[WRN\]/g, '<span style="color: #dcdcaa; font-weight: bold;">[WRN]</span>');
|
|
html = html.replace(/\[INF\]/g, '<span style="color: #4ec9b0;">[INF]</span>');
|
|
html = html.replace(/\[DBG\]/g, '<span style="color: #808080;">[DBG]</span>');
|
|
content.innerHTML = html;
|
|
}
|
|
});
|
|
</script>
|