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

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