event log UI improvements
This commit is contained in:
parent
e710fd61ca
commit
7f9e47edb6
179
Oqtane.Client/Modules/Admin/Logs/Detail.razor
Normal file
179
Oqtane.Client/Modules/Admin/Logs/Detail.razor
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -8,20 +8,36 @@
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Level: </label>
|
||||||
|
<select class="form-control" @onchange="(e => LevelChanged(e))">
|
||||||
|
<option value="-"><All Levels></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">
|
<Pager Items="@Logs">
|
||||||
<Header>
|
<Header>
|
||||||
<th>Date</th>
|
<th>Date</th>
|
||||||
<th>Level</th>
|
|
||||||
<th>Url</th>
|
|
||||||
<th>Category</th>
|
<th>Category</th>
|
||||||
<th>Message</th>
|
<th>Level</th>
|
||||||
|
<th> </th>
|
||||||
</Header>
|
</Header>
|
||||||
<Row>
|
<Row>
|
||||||
<td>@context.LogDate</td>
|
<td>@context.LogDate</td>
|
||||||
<td>@context.Level</td>
|
|
||||||
<td>@context.Url</td>
|
|
||||||
<td>@context.Category</td>
|
<td>@context.Category</td>
|
||||||
<td>@context.Message</td>
|
<td>@context.Level</td>
|
||||||
|
<td><ActionLink Action="Detail" Parameters="@($"id=" + context.LogId.ToString())" /></td>
|
||||||
</Row>
|
</Row>
|
||||||
</Pager>
|
</Pager>
|
||||||
}
|
}
|
||||||
@ -29,10 +45,50 @@ else
|
|||||||
@code {
|
@code {
|
||||||
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
|
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
|
||||||
|
|
||||||
|
string level = "-";
|
||||||
|
string rows = "50";
|
||||||
List<Log> Logs;
|
List<Log> Logs;
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,7 +8,8 @@ namespace Oqtane.Services
|
|||||||
{
|
{
|
||||||
public interface ILogService
|
public interface ILogService
|
||||||
{
|
{
|
||||||
Task<List<Log>> GetLogsAsync(int SiteId);
|
Task<List<Log>> GetLogsAsync(int SiteId, string Level, int Rows);
|
||||||
|
Task<Log> GetLogAsync(int LogId);
|
||||||
Task Log(int? PageId, int? ModuleId, int? UserId, string component, LogLevel level, Exception exception, string message, params object[] args);
|
Task Log(int? PageId, int? ModuleId, int? UserId, string component, LogLevel level, Exception exception, string message, params object[] args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ namespace Oqtane.Services
|
|||||||
{
|
{
|
||||||
Task<List<PageModule>> GetPageModulesAsync();
|
Task<List<PageModule>> GetPageModulesAsync();
|
||||||
Task<PageModule> GetPageModuleAsync(int PageModuleId);
|
Task<PageModule> GetPageModuleAsync(int PageModuleId);
|
||||||
|
Task<PageModule> GetPageModuleAsync(int PageId, int ModuleId);
|
||||||
Task<PageModule> AddPageModuleAsync(PageModule PageModule);
|
Task<PageModule> AddPageModuleAsync(PageModule PageModule);
|
||||||
Task<PageModule> UpdatePageModuleAsync(PageModule PageModule);
|
Task<PageModule> UpdatePageModuleAsync(PageModule PageModule);
|
||||||
Task UpdatePageModuleOrderAsync(int PageId, string Pane);
|
Task UpdatePageModuleOrderAsync(int PageId, string Pane);
|
||||||
|
@ -27,9 +27,14 @@ namespace Oqtane.Services
|
|||||||
get { return CreateApiUrl(sitestate.Alias, NavigationManager.Uri, "Log"); }
|
get { return CreateApiUrl(sitestate.Alias, NavigationManager.Uri, "Log"); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<List<Log>> GetLogsAsync(int SiteId)
|
public async Task<List<Log>> GetLogsAsync(int SiteId, string Level, int Rows)
|
||||||
{
|
{
|
||||||
return await http.GetJsonAsync<List<Log>>(apiurl + "?siteid=" + SiteId.ToString());
|
return await http.GetJsonAsync<List<Log>>(apiurl + "?siteid=" + SiteId.ToString() + "&level=" + Level + "&rows=" + Rows.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Log> GetLogAsync(int LogId)
|
||||||
|
{
|
||||||
|
return await http.GetJsonAsync<Log>(apiurl + "/" + LogId.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Log(int? PageId, int? ModuleId, int? UserId, string category, LogLevel level, Exception exception, string message, params object[] args)
|
public async Task Log(int? PageId, int? ModuleId, int? UserId, string category, LogLevel level, Exception exception, string message, params object[] args)
|
||||||
|
@ -36,6 +36,11 @@ namespace Oqtane.Services
|
|||||||
return await http.GetJsonAsync<PageModule>(apiurl + "/" + PageModuleId.ToString());
|
return await http.GetJsonAsync<PageModule>(apiurl + "/" + PageModuleId.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<PageModule> GetPageModuleAsync(int PageId, int ModuleId)
|
||||||
|
{
|
||||||
|
return await http.GetJsonAsync<PageModule>(apiurl + "/" + PageId.ToString() + "/" + ModuleId.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<PageModule> AddPageModuleAsync(PageModule PageModule)
|
public async Task<PageModule> AddPageModuleAsync(PageModule PageModule)
|
||||||
{
|
{
|
||||||
return await http.PostJsonAsync<PageModule>(apiurl, PageModule);
|
return await http.PostJsonAsync<PageModule>(apiurl, PageModule);
|
||||||
|
@ -3,6 +3,8 @@ using Oqtane.Models;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Oqtane.Repository;
|
using Oqtane.Repository;
|
||||||
using Oqtane.Infrastructure;
|
using Oqtane.Infrastructure;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Oqtane.Shared;
|
||||||
|
|
||||||
namespace Oqtane.Controllers
|
namespace Oqtane.Controllers
|
||||||
{
|
{
|
||||||
@ -19,11 +21,20 @@ namespace Oqtane.Controllers
|
|||||||
this.Logs = Logs;
|
this.Logs = Logs;
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET: api/<controller>?siteid=x
|
// GET: api/<controller>?siteid=x&level=y
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public IEnumerable<Log> Get(string siteid)
|
[Authorize(Roles = Constants.AdminRole)]
|
||||||
|
public IEnumerable<Log> Get(string siteid, string level, string rows)
|
||||||
{
|
{
|
||||||
return Logs.GetLogs(int.Parse(siteid));
|
return Logs.GetLogs(int.Parse(siteid), level, int.Parse(rows));
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET api/<controller>/5
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
[Authorize(Roles = Constants.AdminRole)]
|
||||||
|
public Log Get(int id)
|
||||||
|
{
|
||||||
|
return Logs.GetLog(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST api/<controller>
|
// POST api/<controller>
|
||||||
|
@ -37,6 +37,13 @@ namespace Oqtane.Controllers
|
|||||||
return PageModules.GetPageModule(id);
|
return PageModules.GetPageModule(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GET: api/<controller>/pageid/moduleid
|
||||||
|
[HttpGet("{pageid}/{moduleid}")]
|
||||||
|
public PageModule Get(int pageid, int moduleid)
|
||||||
|
{
|
||||||
|
return PageModules.GetPageModule(pageid, moduleid);
|
||||||
|
}
|
||||||
|
|
||||||
// POST api/<controller>
|
// POST api/<controller>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Authorize(Roles = Constants.AdminRole)]
|
[Authorize(Roles = Constants.AdminRole)]
|
||||||
|
@ -22,6 +22,7 @@ namespace Oqtane.Controllers
|
|||||||
|
|
||||||
// GET: api/<controller>
|
// GET: api/<controller>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
|
[Authorize(Roles = Constants.HostRole)]
|
||||||
public IEnumerable<Tenant> Get()
|
public IEnumerable<Tenant> Get()
|
||||||
{
|
{
|
||||||
return Tenants.GetTenants();
|
return Tenants.GetTenants();
|
||||||
@ -29,6 +30,7 @@ namespace Oqtane.Controllers
|
|||||||
|
|
||||||
// GET api/<controller>/5
|
// GET api/<controller>/5
|
||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
|
[Authorize(Roles = Constants.HostRole)]
|
||||||
public Tenant Get(int id)
|
public Tenant Get(int id)
|
||||||
{
|
{
|
||||||
return Tenants.GetTenant(id);
|
return Tenants.GetTenant(id);
|
||||||
|
@ -5,7 +5,8 @@ namespace Oqtane.Repository
|
|||||||
{
|
{
|
||||||
public interface ILogRepository
|
public interface ILogRepository
|
||||||
{
|
{
|
||||||
|
IEnumerable<Log> GetLogs(int SiteId, string Level, int Rows);
|
||||||
|
Log GetLog(int LogId);
|
||||||
void AddLog(Log Log);
|
void AddLog(Log Log);
|
||||||
IEnumerable<Log> GetLogs(int SiteId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ namespace Oqtane.Repository
|
|||||||
PageModule AddPageModule(PageModule PageModule);
|
PageModule AddPageModule(PageModule PageModule);
|
||||||
PageModule UpdatePageModule(PageModule PageModule);
|
PageModule UpdatePageModule(PageModule PageModule);
|
||||||
PageModule GetPageModule(int PageModuleId);
|
PageModule GetPageModule(int PageModuleId);
|
||||||
|
PageModule GetPageModule(int PageId, int ModuleId);
|
||||||
void DeletePageModule(int PageModuleId);
|
void DeletePageModule(int PageModuleId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,15 +14,29 @@ namespace Oqtane.Repository
|
|||||||
db = context;
|
db = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IEnumerable<Log> GetLogs(int SiteId, string Level, int Rows)
|
||||||
|
{
|
||||||
|
if (Level == null)
|
||||||
|
{
|
||||||
|
return db.Log.Where(item => item.SiteId == SiteId).
|
||||||
|
OrderByDescending(item => item.LogDate).Take(Rows);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return db.Log.Where(item => item.SiteId == SiteId && item.Level == Level)
|
||||||
|
.OrderByDescending(item => item.LogDate).Take(Rows);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Log GetLog(int LogId)
|
||||||
|
{
|
||||||
|
return db.Log.Find(LogId);
|
||||||
|
}
|
||||||
|
|
||||||
public void AddLog(Log Log)
|
public void AddLog(Log Log)
|
||||||
{
|
{
|
||||||
db.Log.Add(Log);
|
db.Log.Add(Log);
|
||||||
db.SaveChanges();
|
db.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Log> GetLogs(int SiteId)
|
|
||||||
{
|
|
||||||
return db.Log.Where(item => item.SiteId == SiteId).OrderByDescending(item=> item.LogDate).Take(50);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,18 @@ namespace Oqtane.Repository
|
|||||||
return pagemodule;
|
return pagemodule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PageModule GetPageModule(int PageId, int ModuleId)
|
||||||
|
{
|
||||||
|
PageModule pagemodule = db.PageModule.Include(item => item.Module) // eager load modules
|
||||||
|
.SingleOrDefault(item => item.PageId == PageId && item.ModuleId == ModuleId);
|
||||||
|
if (pagemodule != null)
|
||||||
|
{
|
||||||
|
IEnumerable<Permission> permissions = Permissions.GetPermissions("Module", pagemodule.ModuleId);
|
||||||
|
pagemodule.Module.Permissions = Permissions.EncodePermissions(pagemodule.ModuleId, permissions);
|
||||||
|
}
|
||||||
|
return pagemodule;
|
||||||
|
}
|
||||||
|
|
||||||
public void DeletePageModule(int PageModuleId)
|
public void DeletePageModule(int PageModuleId)
|
||||||
{
|
{
|
||||||
PageModule PageModule = db.PageModule.Find(PageModuleId);
|
PageModule PageModule = db.PageModule.Find(PageModuleId);
|
||||||
|
Reference in New Issue
Block a user