logging enhancements

This commit is contained in:
Shaun Walker
2019-10-24 16:54:14 -04:00
parent b3e010d5e2
commit 3d7ae6a743
36 changed files with 306 additions and 185 deletions

View File

@ -6,108 +6,124 @@
@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 != "")
{
<table class="table table-borderless">
<tr>
<td>
<label class="control-label">Page: </label>
<label class="control-label">Date/Time: </label>
</td>
<td>
<input class="form-control" @bind="@pagename" disabled />
<input class="form-control" @bind="@logdate" disabled />
</td>
</tr>
}
@if (moduletitle != "")
{
<tr>
<td>
<label class="control-label">Module: </label>
<label class="control-label">Level: </label>
</td>
<td>
<input class="form-control" @bind="@moduletitle" disabled />
<input class="form-control" @bind="@level" disabled />
</td>
</tr>
}
@if (username != "")
{
<tr>
<td>
<label class="control-label">User: </label>
<label class="control-label">Feature: </label>
</td>
<td>
<input class="form-control" @bind="@username" disabled />
<input class="form-control" @bind="@feature" 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>
<label class="control-label">Function: </label>
</td>
<td>
<textarea class="form-control" @bind="@exception" rows="5" disabled />
<input class="form-control" @bind="@function" 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>
<tr>
<td>
<label class="control-label">Category: </label>
</td>
<td>
<input class="form-control" @bind="@category" 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 {
@ -115,8 +131,10 @@
int logid;
string logdate = "";
string category = "";
string level = "";
string feature = "";
string function = "";
string category = "";
string pagename = "";
string moduletitle = "";
string username = "";
@ -136,8 +154,10 @@
if (log != null)
{
logdate = log.LogDate.ToString();
category = log.Category;
level = log.Level;
feature = log.Feature;
function = log.Function;
category = log.Category;
if (log.PageId != null)
{
Page page = await PageService.GetPageAsync(log.PageId.Value);

View File

@ -19,6 +19,16 @@ else
<option value="Error">Error</option>
<option value="Critical">Critical</option>
</select>
<label>Function: </label>
<select class="form-control" @onchange="(e => FunctionChanged(e))">
<option value="-">&lt;All Functions&gt;</option>
<option value="Create">Create</option>
<option value="Read">Read</option>
<option value="Update">Update</option>
<option value="Delete">Delete</option>
<option value="Security">Security</option>
<option value="Other">Other</option>
</select>
<label>Rows: </label>
<select class="form-control" @onchange="(e => RowsChanged(e))">
<option value="10">10</option>
@ -26,34 +36,44 @@ else
<option value="100">100</option>
</select>
</div>
@if(Logs.Any())
{
<Pager Items="@Logs">
<Header>
<th>Date</th>
<th>Category</th>
<th>Level</th>
<th>&nbsp;</th>
<th>Date</th>
<th>Level</th>
<th>Feature</th>
<th>Function</th>
</Header>
<Row>
<td>@context.LogDate</td>
<td>@context.Category</td>
<td>@context.Level</td>
<td><ActionLink Action="Detail" Parameters="@($"id=" + context.LogId.ToString())" /></td>
<td>@context.LogDate</td>
<td>@context.Level</td>
<td>@context.Feature</td>
<td>@context.Function</td>
</Row>
</Pager>
}
else
{
<p><em>No Logs Match The Criteria Specified</em></p>
}
}
@code {
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
string level = "-";
string rows = "50";
string function = "-";
string rows = "10";
List<Log> Logs;
protected override async Task OnInitializedAsync()
{
try
{
Logs = await LogService.GetLogsAsync(PageState.Site.SiteId, ((level == "-") ? "" : level), int.Parse(rows));
await GetLogs();
}
catch (Exception ex)
{
@ -67,7 +87,7 @@ else
try
{
level = (string)e.Value;
Logs = await LogService.GetLogsAsync(PageState.Site.SiteId, ((level == "-") ? "" : level), int.Parse(rows));
await GetLogs();
StateHasChanged();
}
catch (Exception ex)
@ -77,12 +97,12 @@ else
}
}
private async void RowsChanged(ChangeEventArgs e)
private async void FunctionChanged(ChangeEventArgs e)
{
try
{
rows = (string)e.Value;
Logs = await LogService.GetLogsAsync(PageState.Site.SiteId, ((level == "-") ? "" : level), int.Parse(rows));
function = (string)e.Value;
await GetLogs();
StateHasChanged();
}
catch (Exception ex)
@ -91,4 +111,25 @@ else
AddModuleMessage("Error Loading Logs", MessageType.Error);
}
}
private async void RowsChanged(ChangeEventArgs e)
{
try
{
rows = (string)e.Value;
await GetLogs();
StateHasChanged();
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Loading Logs {Error}", ex.Message);
AddModuleMessage("Error Loading Logs", MessageType.Error);
}
}
private async Task GetLogs()
{
Logs = await LogService.GetLogsAsync(PageState.Site.SiteId, ((level == "-") ? "" : level), ((function == "-") ? "" : function), int.Parse(rows));
}
}