event log UI improvements

This commit is contained in:
Shaun Walker
2019-10-23 10:13:58 -04:00
parent e710fd61ca
commit 7f9e47edb6
13 changed files with 314 additions and 19 deletions

View File

@ -0,0 +1,179 @@
@namespace Oqtane.Modules.Admin.Logs
@inherits ModuleBase
@inject NavigationManager NavigationManager
@inject ILogService LogService
@inject IPageService PageService
@inject IPageModuleService PageModuleService
@inject IUserService UserService
<table class="table table-borderless">
<tr>
<td>
<label class="control-label">Date: </label>
</td>
<td>
<input class="form-control" @bind="@logdate" disabled />
</td>
</tr>
<tr>
<td>
<label class="control-label">Category: </label>
</td>
<td>
<input class="form-control" @bind="@category" disabled />
</td>
</tr>
<tr>
<td>
<label class="control-label">Level: </label>
</td>
<td>
<input class="form-control" @bind="@level" disabled />
</td>
</tr>
@if (pagename != "")
{
<tr>
<td>
<label class="control-label">Page: </label>
</td>
<td>
<input class="form-control" @bind="@pagename" disabled />
</td>
</tr>
}
@if (moduletitle != "")
{
<tr>
<td>
<label class="control-label">Module: </label>
</td>
<td>
<input class="form-control" @bind="@moduletitle" disabled />
</td>
</tr>
}
@if (username != "")
{
<tr>
<td>
<label class="control-label">User: </label>
</td>
<td>
<input class="form-control" @bind="@username" disabled />
</td>
</tr>
}
<tr>
<td>
<label class="control-label">Template: </label>
</td>
<td>
<input class="form-control" @bind="@template" disabled />
</td>
</tr>
<tr>
<td>
<label class="control-label">Message: </label>
</td>
<td>
<textarea class="form-control" @bind="@message" rows="5" disabled />
</td>
</tr>
@if (!string.IsNullOrEmpty(exception))
{
<tr>
<td>
<label class="control-label">Exception: </label>
</td>
<td>
<textarea class="form-control" @bind="@exception" rows="5" disabled />
</td>
</tr>
}
<tr>
<td>
<label class="control-label">Properties: </label>
</td>
<td>
<textarea class="form-control" @bind="@properties" rows="5" disabled />
</td>
</tr>
<tr>
<td>
<label class="control-label">Server: </label>
</td>
<td>
<input class="form-control" @bind="@server" disabled />
</td>
</tr>
</table>
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
@code {
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
int logid;
string logdate = "";
string category = "";
string level = "";
string pagename = "";
string moduletitle = "";
string username = "";
string url = "";
string template = "";
string message = "";
string exception = "";
string properties = "";
string server = "";
protected override async Task OnInitializedAsync()
{
try
{
logid = Int32.Parse(PageState.QueryString["id"]);
Log log = await LogService.GetLogAsync(logid);
if (log != null)
{
logdate = log.LogDate.ToString();
category = log.Category;
level = log.Level;
if (log.PageId != null)
{
Page page = await PageService.GetPageAsync(log.PageId.Value);
if (page != null)
{
pagename = page.Name;
}
}
if (log.PageId != null && log.ModuleId != null)
{
PageModule pagemodule = await PageModuleService.GetPageModuleAsync(log.PageId.Value, log.ModuleId.Value);
if (pagemodule != null)
{
moduletitle = pagemodule.Title;
}
}
if (log.UserId != null)
{
User user = await UserService.GetUserAsync(log.UserId.Value, PageState.Site.SiteId);
if (user != null)
{
username = user.Username;
}
}
url = log.Url;
template = log.MessageTemplate;
message = log.Message;
exception = log.Exception;
properties = log.Properties;
server = log.Server;
}
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Loading Log {LogId} {Error}", logid, ex.Message);
AddModuleMessage("Error Loading Log", MessageType.Error);
}
}
}

View File

@ -8,20 +8,36 @@
}
else
{
<div class="form-group">
<label>Level: </label>
<select class="form-control" @onchange="(e => LevelChanged(e))">
<option value="-">&lt;All Levels&gt;</option>
<option value="Trace">Trace</option>
<option value="Debug">Debug</option>
<option value="Information">Information</option>
<option value="Warning">Warning</option>
<option value="Error">Error</option>
<option value="Critical">Critical</option>
</select>
<label>Rows: </label>
<select class="form-control" @onchange="(e => RowsChanged(e))">
<option value="10">10</option>
<option value="50">50</option>
<option value="100">100</option>
</select>
</div>
<Pager Items="@Logs">
<Header>
<th>Date</th>
<th>Level</th>
<th>Url</th>
<th>Category</th>
<th>Message</th>
<th>Level</th>
<th>&nbsp;</th>
</Header>
<Row>
<td>@context.LogDate</td>
<td>@context.Level</td>
<td>@context.Url</td>
<td>@context.Category</td>
<td>@context.Message</td>
<td>@context.Level</td>
<td><ActionLink Action="Detail" Parameters="@($"id=" + context.LogId.ToString())" /></td>
</Row>
</Pager>
}
@ -29,10 +45,50 @@ else
@code {
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
string level = "-";
string rows = "50";
List<Log> Logs;
protected override async Task OnInitializedAsync()
{
Logs = await LogService.GetLogsAsync(PageState.Site.SiteId);
try
{
Logs = await LogService.GetLogsAsync(PageState.Site.SiteId, ((level == "-") ? "" : level), int.Parse(rows));
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Loading Logs {Error}", ex.Message);
AddModuleMessage("Error Loading Logs", MessageType.Error);
}
}
private async void LevelChanged(ChangeEventArgs e)
{
try
{
level = (string)e.Value;
Logs = await LogService.GetLogsAsync(PageState.Site.SiteId, ((level == "-") ? "" : level), int.Parse(rows));
StateHasChanged();
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Loading Logs {Error}", ex.Message);
AddModuleMessage("Error Loading Logs", MessageType.Error);
}
}
private async void RowsChanged(ChangeEventArgs e)
{
try
{
rows = (string)e.Value;
Logs = await LogService.GetLogsAsync(PageState.Site.SiteId, ((level == "-") ? "" : level), int.Parse(rows));
StateHasChanged();
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Loading Logs {Error}", ex.Message);
AddModuleMessage("Error Loading Logs", MessageType.Error);
}
}
}