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));
}
}

View File

@ -57,7 +57,7 @@
if (PageState.EditMode)
{
string typename = ModuleState.ModuleType.Replace(Utilities.GetTypeNameClass(ModuleState.ModuleType) + ",", Action + ",");
string typename = ModuleState.ModuleType.Replace(Utilities.GetTypeNameLastSegment(ModuleState.ModuleType, 0) + ",", Action + ",");
Type moduleType = Type.GetType(typename);
if (moduleType != null)
{

View File

@ -135,7 +135,25 @@ namespace Oqtane.Modules
{
UserId = PageState.User.UserId;
}
await LoggingService.Log(PageId, ModuleId, UserId, this.GetType().ToString(), level, exception, message, args);
string category = this.GetType().AssemblyQualifiedName;
string feature = Utilities.GetTypeNameLastSegment(category, 1);
LogFunction function;
switch (PageState.Action)
{
case "Add":
function = LogFunction.Create;
break;
case "Edit":
function = LogFunction.Update;
break;
case "Delete":
function = LogFunction.Delete;
break;
default:
function = LogFunction.Read;
break;
}
await LoggingService.Log(PageId, ModuleId, UserId, category, feature, function, level, exception, message, args);
}
public class Logger

View File

@ -8,8 +8,8 @@ namespace Oqtane.Services
{
public interface ILogService
{
Task<List<Log>> GetLogsAsync(int SiteId, string Level, int Rows);
Task<List<Log>> GetLogsAsync(int SiteId, string Level, string Function, 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 category, string feature, LogFunction function, LogLevel level, Exception exception, string message, params object[] args);
}
}

View File

@ -27,9 +27,9 @@ namespace Oqtane.Services
get { return CreateApiUrl(sitestate.Alias, NavigationManager.Uri, "Log"); }
}
public async Task<List<Log>> GetLogsAsync(int SiteId, string Level, int Rows)
public async Task<List<Log>> GetLogsAsync(int SiteId, string Level, string Function, int Rows)
{
return await http.GetJsonAsync<List<Log>>(apiurl + "?siteid=" + SiteId.ToString() + "&level=" + Level + "&rows=" + Rows.ToString());
return await http.GetJsonAsync<List<Log>>(apiurl + "?siteid=" + SiteId.ToString() + "&level=" + Level + "&function=" + Function + "&rows=" + Rows.ToString());
}
public async Task<Log> GetLogAsync(int LogId)
@ -37,7 +37,7 @@ namespace Oqtane.Services
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, string feature, LogFunction function, LogLevel level, Exception exception, string message, params object[] args)
{
Log log = new Log();
log.SiteId = sitestate.Alias.SiteId;
@ -46,6 +46,8 @@ namespace Oqtane.Services
log.UserId = UserId;
log.Url = NavigationManager.Uri;
log.Category = category;
log.Feature = feature;
log.Function = Enum.GetName(typeof(LogFunction), function);
log.Level = Enum.GetName(typeof(LogLevel), level);
if (exception != null)
{

View File

@ -68,7 +68,7 @@ namespace Oqtane.Services
{
foreach (string themecontrol in theme.ThemeControls.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
{
selectableThemes.Add(themecontrol, theme.Name + " - " + Utilities.GetTypeNameClass(themecontrol));
selectableThemes.Add(themecontrol, theme.Name + " - " + Utilities.GetTypeNameLastSegment(themecontrol, 0));
}
}
return selectableThemes;
@ -83,7 +83,7 @@ namespace Oqtane.Services
{
foreach (string panelayout in theme.PaneLayouts.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
{
selectablePaneLayouts.Add(panelayout, theme.Name + " - " + @Utilities.GetTypeNameClass(panelayout));
selectablePaneLayouts.Add(panelayout, theme.Name + " - " + @Utilities.GetTypeNameLastSegment(panelayout, 0));
}
}
}
@ -97,7 +97,7 @@ namespace Oqtane.Services
{
foreach (string container in theme.ContainerControls.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
{
selectableContainers.Add(container, theme.Name + " - " + @Utilities.GetTypeNameClass(container));
selectableContainers.Add(container, theme.Name + " - " + @Utilities.GetTypeNameLastSegment(container, 0));
}
}
return selectableContainers;

View File

@ -48,7 +48,7 @@
else
{
// module does not exist with typename specified
message = "Module Does Not Have A Component Named " + Utilities.GetTypeNameClass(typename) + ".razor";
message = "Module Does Not Have A Component Named " + Utilities.GetTypeNameLastSegment(typename, 0) + ".razor";
}
};
}

View File

@ -42,7 +42,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid)
{
Alias = Aliases.AddAlias(Alias);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Alias Added {Alias}", Alias);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Create, "Alias Added {Alias}", Alias);
}
return Alias;
}
@ -55,7 +55,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid)
{
Alias = Aliases.UpdateAlias(Alias);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Alias Updated {Alias}", Alias);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Update, "Alias Updated {Alias}", Alias);
}
return Alias;
}
@ -66,7 +66,7 @@ namespace Oqtane.Controllers
public void Delete(int id)
{
Aliases.DeleteAlias(id);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Alias Deleted {AliasId}", id);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Delete, "Alias Deleted {AliasId}", id);
}
}
}

View File

@ -110,7 +110,7 @@ namespace Oqtane.Controllers
{
// rename file now that the entire process is completed
System.IO.File.Move(Path.Combine(folder, filename + ".tmp"), Path.Combine(folder, filename));
logger.AddLog(this.GetType().FullName, LogLevel.Information, "File Uploaded {File}", Path.Combine(folder, filename));
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Create, "File Uploaded {File}", Path.Combine(folder, filename));
}
}
}
@ -173,7 +173,7 @@ namespace Oqtane.Controllers
if (System.IO.File.Exists(file))
{
System.IO.File.Delete(file);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "File Deleted {File}", file);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Delete, "File Deleted {File}", file);
}
}

View File

@ -21,12 +21,12 @@ namespace Oqtane.Controllers
this.Logs = Logs;
}
// GET: api/<controller>?siteid=x&level=y
// GET: api/<controller>?siteid=x&level=y&function=z&rows=50
[HttpGet]
[Authorize(Roles = Constants.AdminRole)]
public IEnumerable<Log> Get(string siteid, string level, string rows)
public IEnumerable<Log> Get(string siteid, string level, string function, string rows)
{
return Logs.GetLogs(int.Parse(siteid), level, int.Parse(rows));
return Logs.GetLogs(int.Parse(siteid), level, function, int.Parse(rows));
}
// GET api/<controller>/5
@ -43,7 +43,7 @@ namespace Oqtane.Controllers
{
if (ModelState.IsValid)
{
Logger.AddLog(Log);
Logger.Log(Log);
}
}
}

View File

@ -76,7 +76,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid)
{
Module = Modules.AddModule(Module);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Module Added {Module}", Module);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Create, "Module Added {Module}", Module);
}
return Module;
}
@ -89,7 +89,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid)
{
Module = Modules.UpdateModule(Module);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Module Updated {Module}", Module);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Update, "Module Updated {Module}", Module);
}
return Module;
}
@ -100,7 +100,7 @@ namespace Oqtane.Controllers
public void Delete(int id)
{
Modules.DeleteModule(id);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Module Deleted {ModuleId}", id);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Delete, "Module Deleted {ModuleId}", id);
}
// GET api/<controller>/export?moduleid=x
@ -141,7 +141,7 @@ namespace Oqtane.Controllers
}
}
content = JsonSerializer.Serialize(modulecontent);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Module Content Exported {ModuleId}", moduleid);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Read, "Module Content Exported {ModuleId}", moduleid);
}
}
}
@ -187,7 +187,7 @@ namespace Oqtane.Controllers
var moduleobject = ActivatorUtilities.CreateInstance(ServiceProvider, moduletype);
((IPortable)moduleobject).ImportModule(module, modulecontent.Content, modulecontent.Version);
success = true;
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Module Content Imported {ModuleId}", moduleid);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Update, "Module Content Imported {ModuleId}", moduleid);
}
}
}

View File

@ -52,7 +52,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid)
{
ModuleDefinitions.UpdateModuleDefinition(ModuleDefinition);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Module Definition Updated {ModuleDefinition}", ModuleDefinition);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Update, "Module Definition Updated {ModuleDefinition}", ModuleDefinition);
}
}
@ -61,7 +61,7 @@ namespace Oqtane.Controllers
public void InstallModules()
{
InstallationManager.InstallPackages("Modules");
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Modules Installed");
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Create, "Modules Installed");
}
// DELETE api/<controller>/5?siteid=x
@ -88,7 +88,7 @@ namespace Oqtane.Controllers
}
ModuleDefinitions.DeleteModuleDefinition(id, siteid);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Module Deleted {ModuleDefinitionId}", id);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Delete, "Module Deleted {ModuleDefinitionId}", id);
InstallationManager.RestartApplication();
}

View File

@ -50,7 +50,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid)
{
Page = Pages.AddPage(Page);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Page Added {Page}", Page);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Create, "Page Added {Page}", Page);
}
return Page;
}
@ -63,7 +63,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid)
{
Page = Pages.UpdatePage(Page);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Page Updated {Page}", Page);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Update, "Page Updated {Page}", Page);
}
return Page;
}
@ -84,7 +84,7 @@ namespace Oqtane.Controllers
}
order += 2;
}
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Page Order Updated {SiteId} {ParentId}", siteid, parentid);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Update, "Page Order Updated {SiteId} {ParentId}", siteid, parentid);
}
// DELETE api/<controller>/5
@ -93,7 +93,7 @@ namespace Oqtane.Controllers
public void Delete(int id)
{
Pages.DeletePage(id);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Page Deleted {PageId}", id);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Delete, "Page Deleted {PageId}", id);
}
}
}

View File

@ -52,7 +52,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid)
{
PageModule = PageModules.AddPageModule(PageModule);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Page Module Added {PageModule}", PageModule);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Create, "Page Module Added {PageModule}", PageModule);
}
return PageModule;
}
@ -65,7 +65,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid)
{
PageModule = PageModules.UpdatePageModule(PageModule);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Page Module Updated {PageModule}", PageModule);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Update, "Page Module Updated {PageModule}", PageModule);
}
return PageModule;
}
@ -86,7 +86,7 @@ namespace Oqtane.Controllers
}
order += 2;
}
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Page Module Order Updated {PageId} {Pane}", pageid, pane);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Update, "Page Module Order Updated {PageId} {Pane}", pageid, pane);
}
// DELETE api/<controller>/5
@ -95,7 +95,7 @@ namespace Oqtane.Controllers
public void Delete(int id)
{
PageModules.DeletePageModule(id);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Page Module Deleted {PageModuleId}", id);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Delete, "Page Module Deleted {PageModuleId}", id);
}
}
}

View File

@ -42,7 +42,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid)
{
Permission = Permissions.AddPermission(Permission);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Permission Added {Permission}", Permission);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Create, "Permission Added {Permission}", Permission);
}
return Permission;
}
@ -55,7 +55,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid)
{
Permission = Permissions.UpdatePermission(Permission);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Permission Updated {Permission}", Permission);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Update, "Permission Updated {Permission}", Permission);
}
return Permission;
}
@ -66,7 +66,7 @@ namespace Oqtane.Controllers
public void Delete(int id)
{
Permissions.DeletePermission(id);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Permission Deleted {PermissionId}", id);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Delete, "Permission Deleted {PermissionId}", id);
}
}
}

View File

@ -49,7 +49,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid)
{
Profile = Profiles.AddProfile(Profile);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Profile Added {Profile}", Profile);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Create, "Profile Added {Profile}", Profile);
}
return Profile;
}
@ -62,7 +62,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid)
{
Profile = Profiles.UpdateProfile(Profile);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Profile Updated {Profile}", Profile);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Update, "Profile Updated {Profile}", Profile);
}
return Profile;
}
@ -73,7 +73,7 @@ namespace Oqtane.Controllers
public void Delete(int id)
{
Profiles.DeleteProfile(id);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Profile Deleted {ProfileId}", id);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Delete, "Profile Deleted {ProfileId}", id);
}
}
}

View File

@ -49,7 +49,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid)
{
Role = Roles.AddRole(Role);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Role Added {Role}", Role);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Create, "Role Added {Role}", Role);
}
return Role;
}
@ -62,7 +62,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid)
{
Role = Roles.UpdateRole(Role);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Role Updated {Role}", Role);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Update, "Role Updated {Role}", Role);
}
return Role;
}
@ -73,7 +73,7 @@ namespace Oqtane.Controllers
public void Delete(int id)
{
Roles.DeleteRole(id);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Role Deleted {RoleId}", id);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Delete, "Role Deleted {RoleId}", id);
}
}
}

View File

@ -45,7 +45,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid && IsAuthorized(Setting.EntityName, Setting.EntityId))
{
Setting = Settings.AddSetting(Setting);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Setting Added {Setting}", Setting);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Create, "Setting Added {Setting}", Setting);
}
return Setting;
}
@ -58,7 +58,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid && IsAuthorized(Setting.EntityName, Setting.EntityId))
{
Setting = Settings.UpdateSetting(Setting);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Setting Updated {Setting}", Setting);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Update, "Setting Updated {Setting}", Setting);
}
return Setting;
}
@ -69,7 +69,7 @@ namespace Oqtane.Controllers
public void Delete(int id)
{
Settings.DeleteSetting(id);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Setting Deleted {SettingId}", id);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Delete, "Setting Deleted {SettingId}", id);
}
private bool IsAuthorized(string EntityName, int EntityId)

View File

@ -67,7 +67,7 @@ namespace Oqtane.Controllers
{
Directory.CreateDirectory(folder);
}
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Site Added {Site}", Site);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Create, "Site Added {Site}", Site);
}
}
return Site;
@ -81,7 +81,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid)
{
Site = Sites.UpdateSite(Site);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Site Updated {Site}", Site);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Update, "Site Updated {Site}", Site);
}
return Site;
}
@ -92,7 +92,7 @@ namespace Oqtane.Controllers
public void Delete(int id)
{
Sites.DeleteSite(id);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Site Deleted {SiteId}", id);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Delete, "Site Deleted {SiteId}", id);
}
}
}

View File

@ -44,7 +44,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid)
{
Tenant = Tenants.AddTenant(Tenant);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Tenant Added {TenantId}", Tenant.TenantId);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Create, "Tenant Added {TenantId}", Tenant.TenantId);
}
return Tenant;
}
@ -57,7 +57,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid)
{
Tenant = Tenants.UpdateTenant(Tenant);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Tenant Updated {TenantId}", Tenant.TenantId);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Update, "Tenant Updated {TenantId}", Tenant.TenantId);
}
return Tenant;
}
@ -68,7 +68,7 @@ namespace Oqtane.Controllers
public void Delete(int id)
{
Tenants.DeleteTenant(id);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Tenant Deleted {TenantId}", id);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Delete, "Tenant Deleted {TenantId}", id);
}
}
}

View File

@ -49,7 +49,7 @@ namespace Oqtane.Controllers
public void InstallThemes()
{
InstallationManager.InstallPackages("Themes");
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Themes Installed");
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Create, "Themes Installed");
}
// DELETE api/<controller>/xxx
@ -74,7 +74,7 @@ namespace Oqtane.Controllers
{
System.IO.File.Delete(file);
}
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Theme Deleted {ThemeName}", themename);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Delete, "Theme Deleted {ThemeName}", themename);
InstallationManager.RestartApplication();
}

View File

@ -127,7 +127,7 @@ namespace Oqtane.Controllers
}
}
user.Password = ""; // remove sensitive information
logger.AddLog(this.GetType().FullName, LogLevel.Information, "User Added {User}", user);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Create, "User Added {User}", user);
}
return user;
@ -151,7 +151,7 @@ namespace Oqtane.Controllers
}
User = Users.UpdateUser(User);
User.Password = ""; // remove sensitive information
logger.AddLog(this.GetType().FullName, LogLevel.Information, "User Updated {User}", User);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Update, "User Updated {User}", User);
}
return User;
}
@ -170,7 +170,7 @@ namespace Oqtane.Controllers
if (result != null)
{
Users.DeleteUser(id);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "User Deleted {UserId}", id);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Delete, "User Deleted {UserId}", id);
}
}
}
@ -193,7 +193,7 @@ namespace Oqtane.Controllers
if (user != null)
{
user.IsAuthenticated = true;
logger.AddLog(this.GetType().FullName, LogLevel.Information, "User Login Successful {Username}", User.Username);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Security, "User Login Successful {Username}", User.Username);
if (SetCookie)
{
await IdentitySignInManager.SignInAsync(identityuser, IsPersistent);
@ -202,7 +202,7 @@ namespace Oqtane.Controllers
}
else
{
logger.AddLog(this.GetType().FullName, LogLevel.Error, "User Login Failed {Username}", User.Username);
logger.Log(LogLevel.Error, this.GetType().AssemblyQualifiedName, LogFunction.Security, "User Login Failed {Username}", User.Username);
}
}
}
@ -216,7 +216,7 @@ namespace Oqtane.Controllers
public async Task Logout([FromBody] User User)
{
await HttpContext.SignOutAsync(IdentityConstants.ApplicationScheme);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "User Logout {Username}", User.Username);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Security, "User Logout {Username}", User.Username);
}
// GET api/<controller>/current

View File

@ -49,7 +49,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid)
{
UserRole = UserRoles.AddUserRole(UserRole);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "User Role Added {UserRole}", UserRole);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Create, "User Role Added {UserRole}", UserRole);
}
return UserRole;
}
@ -62,7 +62,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid)
{
UserRole = UserRoles.UpdateUserRole(UserRole);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "User Role Updated {UserRole}", UserRole);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Update, "User Role Updated {UserRole}", UserRole);
}
return UserRole;
}
@ -73,7 +73,7 @@ namespace Oqtane.Controllers
public void Delete(int id)
{
UserRoles.DeleteUserRole(id);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "User Role Deleted {UserRoleId}", id);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Delete, "User Role Deleted {UserRoleId}", id);
}
}
}

View File

@ -6,8 +6,8 @@ namespace Oqtane.Infrastructure
{
public interface ILogManager
{
void AddLog(string Category, LogLevel Level, string Message, params object[] Args);
void AddLog(string Category, LogLevel Level, Exception Exception, string Message, params object[] Args);
void AddLog(Log Log);
void Log(LogLevel Level, string Category, LogFunction Function, string Message, params object[] Args);
void Log(LogLevel Level, string Category, LogFunction Function, Exception Exception, string Message, params object[] Args);
void Log(Log Log);
}
}

View File

@ -25,12 +25,12 @@ namespace Oqtane.Infrastructure
this.Accessor = Accessor;
}
public void AddLog(string Category, LogLevel Level, string Message, params object[] Args)
public void Log(LogLevel Level, string Category, LogFunction Function, string Message, params object[] Args)
{
AddLog(Category, Level, null, Message, Args);
Log(Level, Category, Function, null, Message, Args);
}
public void AddLog(string Category, LogLevel Level, Exception Exception, string Message, params object[] Args)
public void Log(LogLevel Level, string Category, LogFunction Function, Exception Exception, string Message, params object[] Args)
{
Alias alias = TenantResolver.GetAlias();
Log log = new Log();
@ -48,6 +48,8 @@ namespace Oqtane.Infrastructure
}
log.Category = Category;
log.Feature = Utilities.GetTypeNameLastSegment(Category, 0);
log.Function = Enum.GetName(typeof(LogFunction), Function);
log.Level = Enum.GetName(typeof(LogLevel), Level);
if (Exception != null)
{
@ -56,10 +58,10 @@ namespace Oqtane.Infrastructure
log.Message = Message;
log.MessageTemplate = "";
log.Properties = JsonSerializer.Serialize(Args);
AddLog(log);
Log(log);
}
public void AddLog(Log Log)
public void Log(Log Log)
{
LogLevel minlevel = LogLevel.Information;
var section = Config.GetSection("Logging:LogLevel:Default");

View File

@ -42,7 +42,7 @@ namespace Oqtane.Modules.HtmlText.Controllers
}
catch (Exception ex)
{
logger.AddLog(this.GetType().FullName, LogLevel.Error, ex, "Get Error {Error}", ex.Message);
logger.Log(LogLevel.Error, this.GetType().AssemblyQualifiedName, LogFunction.Read, ex, "Get Error {Error}", ex.Message);
throw;
}
}
@ -57,13 +57,13 @@ namespace Oqtane.Modules.HtmlText.Controllers
if (ModelState.IsValid && HtmlText.ModuleId == EntityId)
{
HtmlText = htmltext.AddHtmlText(HtmlText);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Html/Text Added {HtmlText}", HtmlText);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Create, "Html/Text Added {HtmlText}", HtmlText);
}
return HtmlText;
}
catch (Exception ex)
{
logger.AddLog(this.GetType().FullName, LogLevel.Error, ex, "Post Error {Error}", ex.Message);
logger.Log(LogLevel.Error, this.GetType().AssemblyQualifiedName, LogFunction.Create, ex, "Post Error {Error}", ex.Message);
throw;
}
}
@ -78,13 +78,13 @@ namespace Oqtane.Modules.HtmlText.Controllers
if (ModelState.IsValid && HtmlText.ModuleId == EntityId)
{
HtmlText = htmltext.UpdateHtmlText(HtmlText);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Html/Text Updated {HtmlText}", HtmlText);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Update, "Html/Text Updated {HtmlText}", HtmlText);
}
return HtmlText;
}
catch (Exception ex)
{
logger.AddLog(this.GetType().FullName, LogLevel.Error, ex, "Put Error {Error}", ex.Message);
logger.Log(LogLevel.Error, this.GetType().AssemblyQualifiedName, LogFunction.Update, ex, "Put Error {Error}", ex.Message);
throw;
}
}
@ -99,12 +99,12 @@ namespace Oqtane.Modules.HtmlText.Controllers
if (id == EntityId)
{
htmltext.DeleteHtmlText(id);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Html/Text Deleted {HtmlTextId}", id);
logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Delete, "Html/Text Deleted {HtmlTextId}", id);
}
}
catch (Exception ex)
{
logger.AddLog(this.GetType().FullName, LogLevel.Error, ex, "Delete Error {Error}", ex.Message);
logger.Log(LogLevel.Error, this.GetType().AssemblyQualifiedName, LogFunction.Delete, ex, "Delete Error {Error}", ex.Message);
throw;
}
}

View File

@ -5,7 +5,7 @@ namespace Oqtane.Repository
{
public interface ILogRepository
{
IEnumerable<Log> GetLogs(int SiteId, string Level, int Rows);
IEnumerable<Log> GetLogs(int SiteId, string Level, string Function, int Rows);
Log GetLog(int LogId);
void AddLog(Log Log);
}

View File

@ -14,17 +14,33 @@ namespace Oqtane.Repository
db = context;
}
public IEnumerable<Log> GetLogs(int SiteId, string Level, int Rows)
public IEnumerable<Log> GetLogs(int SiteId, string Level, string Function, int Rows)
{
if (Level == null)
{
return db.Log.Where(item => item.SiteId == SiteId).
OrderByDescending(item => item.LogDate).Take(Rows);
if (Function == 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.Function == Function).
OrderByDescending(item => item.LogDate).Take(Rows);
}
}
else
{
return db.Log.Where(item => item.SiteId == SiteId && item.Level == Level)
.OrderByDescending(item => item.LogDate).Take(Rows);
if (Function == null)
{
return db.Log.Where(item => item.SiteId == SiteId && item.Level == Level)
.OrderByDescending(item => item.LogDate).Take(Rows);
}
else
{
return db.Log.Where(item => item.SiteId == SiteId && item.Level == Level && item.Function == Function)
.OrderByDescending(item => item.LogDate).Take(Rows);
}
}
}

View File

@ -215,6 +215,8 @@ CREATE TABLE [dbo].[Log] (
[Url] [nvarchar](200) NOT NULL,
[Server] [nvarchar](200) NOT NULL,
[Category] [nvarchar](200) NOT NULL,
[Feature] [nvarchar](200) NOT NULL,
[Function] [nvarchar](20) NOT NULL,
[Level] [nvarchar](20) NOT NULL,
[Message] [nvarchar](max) NOT NULL,
[MessageTemplate] [nvarchar](max) NOT NULL,

View File

@ -32,7 +32,7 @@ namespace Oqtane.Security
}
else
{
logger.AddLog(this.GetType().FullName, LogLevel.Error, "User {User} Does Not Have {PermissionName} Permission For {EntityName}:{EntityId}", context.User, requirement.PermissionName, requirement.EntityName, EntityId);
logger.Log(LogLevel.Error, this.GetType().AssemblyQualifiedName, LogFunction.Security, "User {User} Does Not Have {PermissionName} Permission For {EntityName}:{EntityId}", context.User, requirement.PermissionName, requirement.EntityName, EntityId);
}
}
return Task.CompletedTask;

View File

@ -0,0 +1,12 @@
namespace Oqtane.Shared
{
public enum LogFunction
{
Create,
Read,
Update,
Delete,
Security,
Other
}
}

View File

@ -1,4 +1,4 @@
namespace Oqtane.Modules
namespace Oqtane.Shared
{
public enum MessageType
{

View File

@ -13,7 +13,9 @@ namespace Oqtane.Models
public int? UserId { get; set; }
public string Url { get; set; }
public string Server { get; set; }
public string Category { get; set; }
public string Category { get; set; } // usually the full typename of the
public string Feature { get; set; }
public string Function { get; set; }
public string Level { get; set; }
public string Message { get; set; }
public string MessageTemplate { get; set; }

View File

@ -5,7 +5,6 @@ namespace Oqtane.Shared
{
public class Utilities
{
public static string NavigateUrl(string alias, string path, string parameters, Reload reload)
{
string url = "";
@ -71,14 +70,21 @@ namespace Oqtane.Shared
}
}
public static string GetTypeNameClass(string typename)
public static string GetTypeNameLastSegment(string typename, int segment)
{
if (typename.Contains(","))
{
// remove assembly if fully qualified type
typename = typename.Substring(0, typename.IndexOf(","));
}
string[] fragments = typename.Split('.');
return fragments[fragments.Length - 1];
// segment 0 is the last segment, segment 1 is the second to last segment, etc...
string[] segments = typename.Split('.');
string name = "";
if (segment < segments.Length)
{
name = segments[segments.Length - (segment + 1)];
}
return name;
}
public static string GetFriendlyUrl(string text)