From e25bbe2e24d9157749e1ac4db39919c79463da6a Mon Sep 17 00:00:00 2001 From: Shaun Walker Date: Sat, 26 Oct 2019 11:00:45 -0400 Subject: [PATCH] logging abstraction --- Oqtane.Server/Controllers/AliasController.cs | 6 +++--- Oqtane.Server/Controllers/FileController.cs | 4 ++-- .../Controllers/InstallationController.cs | 2 +- Oqtane.Server/Controllers/ModuleController.cs | 10 +++++----- .../Controllers/ModuleDefinitionController.cs | 8 ++++---- Oqtane.Server/Controllers/PageController.cs | 8 ++++---- .../Controllers/PageModuleController.cs | 8 ++++---- .../Controllers/PermissionController.cs | 6 +++--- Oqtane.Server/Controllers/ProfileController.cs | 6 +++--- Oqtane.Server/Controllers/RoleController.cs | 6 +++--- Oqtane.Server/Controllers/SettingController.cs | 6 +++--- Oqtane.Server/Controllers/SiteController.cs | 6 +++--- Oqtane.Server/Controllers/TenantController.cs | 6 +++--- Oqtane.Server/Controllers/ThemeController.cs | 6 +++--- Oqtane.Server/Controllers/UserController.cs | 12 ++++++------ Oqtane.Server/Controllers/UserRoleController.cs | 6 +++--- .../Infrastructure/IInstallationManager.cs | 2 +- Oqtane.Server/Infrastructure/ILogManager.cs | 4 ++-- .../Infrastructure/InstallationManager.cs | 4 ++-- Oqtane.Server/Infrastructure/LogManager.cs | 17 ++++++++++++----- .../HtmlText/Controllers/HtmlTextController.cs | 14 +++++++------- Oqtane.Server/Security/PermissionHandler.cs | 2 +- Oqtane.Server/Startup.cs | 2 +- 23 files changed, 79 insertions(+), 72 deletions(-) diff --git a/Oqtane.Server/Controllers/AliasController.cs b/Oqtane.Server/Controllers/AliasController.cs index 0398bc65..bfd2f4c5 100644 --- a/Oqtane.Server/Controllers/AliasController.cs +++ b/Oqtane.Server/Controllers/AliasController.cs @@ -42,7 +42,7 @@ namespace Oqtane.Controllers if (ModelState.IsValid) { Alias = Aliases.AddAlias(Alias); - logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Create, "Alias Added {Alias}", Alias); + logger.Log(LogLevel.Information, this, LogFunction.Create, "Alias Added {Alias}", Alias); } return Alias; } @@ -55,7 +55,7 @@ namespace Oqtane.Controllers if (ModelState.IsValid) { Alias = Aliases.UpdateAlias(Alias); - logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Update, "Alias Updated {Alias}", Alias); + logger.Log(LogLevel.Information, this, LogFunction.Update, "Alias Updated {Alias}", Alias); } return Alias; } @@ -66,7 +66,7 @@ namespace Oqtane.Controllers public void Delete(int id) { Aliases.DeleteAlias(id); - logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Delete, "Alias Deleted {AliasId}", id); + logger.Log(LogLevel.Information, this, LogFunction.Delete, "Alias Deleted {AliasId}", id); } } } diff --git a/Oqtane.Server/Controllers/FileController.cs b/Oqtane.Server/Controllers/FileController.cs index 3202ea9e..72bf7bcb 100644 --- a/Oqtane.Server/Controllers/FileController.cs +++ b/Oqtane.Server/Controllers/FileController.cs @@ -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.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Create, "File Uploaded {File}", Path.Combine(folder, filename)); + logger.Log(LogLevel.Information, this, 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.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Delete, "File Deleted {File}", file); + logger.Log(LogLevel.Information, this, LogFunction.Delete, "File Deleted {File}", file); } } diff --git a/Oqtane.Server/Controllers/InstallationController.cs b/Oqtane.Server/Controllers/InstallationController.cs index d76ad8df..84c9c2d7 100644 --- a/Oqtane.Server/Controllers/InstallationController.cs +++ b/Oqtane.Server/Controllers/InstallationController.cs @@ -279,7 +279,7 @@ namespace Oqtane.Controllers public GenericResponse Upgrade() { var response = new GenericResponse { Success = true, Message = "" }; - InstallationManager.InstallPackages("Framework"); + InstallationManager.InstallPackages("Framework", true); return response; } } diff --git a/Oqtane.Server/Controllers/ModuleController.cs b/Oqtane.Server/Controllers/ModuleController.cs index b74c2290..f83e75c0 100644 --- a/Oqtane.Server/Controllers/ModuleController.cs +++ b/Oqtane.Server/Controllers/ModuleController.cs @@ -76,7 +76,7 @@ namespace Oqtane.Controllers if (ModelState.IsValid) { Module = Modules.AddModule(Module); - logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Create, "Module Added {Module}", Module); + logger.Log(LogLevel.Information, this, LogFunction.Create, "Module Added {Module}", Module); } return Module; } @@ -89,7 +89,7 @@ namespace Oqtane.Controllers if (ModelState.IsValid) { Module = Modules.UpdateModule(Module); - logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Update, "Module Updated {Module}", Module); + logger.Log(LogLevel.Information, this, LogFunction.Update, "Module Updated {Module}", Module); } return Module; } @@ -100,7 +100,7 @@ namespace Oqtane.Controllers public void Delete(int id) { Modules.DeleteModule(id); - logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Delete, "Module Deleted {ModuleId}", id); + logger.Log(LogLevel.Information, this, LogFunction.Delete, "Module Deleted {ModuleId}", id); } // GET api//export?moduleid=x @@ -141,7 +141,7 @@ namespace Oqtane.Controllers } } content = JsonSerializer.Serialize(modulecontent); - logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Read, "Module Content Exported {ModuleId}", moduleid); + logger.Log(LogLevel.Information, this, 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.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Update, "Module Content Imported {ModuleId}", moduleid); + logger.Log(LogLevel.Information, this, LogFunction.Update, "Module Content Imported {ModuleId}", moduleid); } } } diff --git a/Oqtane.Server/Controllers/ModuleDefinitionController.cs b/Oqtane.Server/Controllers/ModuleDefinitionController.cs index bb99f5b2..7845890f 100644 --- a/Oqtane.Server/Controllers/ModuleDefinitionController.cs +++ b/Oqtane.Server/Controllers/ModuleDefinitionController.cs @@ -52,7 +52,7 @@ namespace Oqtane.Controllers if (ModelState.IsValid) { ModuleDefinitions.UpdateModuleDefinition(ModuleDefinition); - logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Update, "Module Definition Updated {ModuleDefinition}", ModuleDefinition); + logger.Log(LogLevel.Information, this, LogFunction.Update, "Module Definition Updated {ModuleDefinition}", ModuleDefinition); } } @@ -60,8 +60,8 @@ namespace Oqtane.Controllers [Authorize(Roles = Constants.HostRole)] public void InstallModules() { - InstallationManager.InstallPackages("Modules"); - logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Create, "Modules Installed"); + InstallationManager.InstallPackages("Modules", true); + logger.Log(LogLevel.Information, this, LogFunction.Create, "Modules Installed"); } // DELETE api//5?siteid=x @@ -88,7 +88,7 @@ namespace Oqtane.Controllers } ModuleDefinitions.DeleteModuleDefinition(id, siteid); - logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Delete, "Module Deleted {ModuleDefinitionId}", id); + logger.Log(LogLevel.Information, this, LogFunction.Delete, "Module Deleted {ModuleDefinitionId}", id); InstallationManager.RestartApplication(); } diff --git a/Oqtane.Server/Controllers/PageController.cs b/Oqtane.Server/Controllers/PageController.cs index 90ed2d4c..a0ce7610 100644 --- a/Oqtane.Server/Controllers/PageController.cs +++ b/Oqtane.Server/Controllers/PageController.cs @@ -50,7 +50,7 @@ namespace Oqtane.Controllers if (ModelState.IsValid) { Page = Pages.AddPage(Page); - logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Create, "Page Added {Page}", Page); + logger.Log(LogLevel.Information, this, LogFunction.Create, "Page Added {Page}", Page); } return Page; } @@ -63,7 +63,7 @@ namespace Oqtane.Controllers if (ModelState.IsValid) { Page = Pages.UpdatePage(Page); - logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Update, "Page Updated {Page}", Page); + logger.Log(LogLevel.Information, this, LogFunction.Update, "Page Updated {Page}", Page); } return Page; } @@ -84,7 +84,7 @@ namespace Oqtane.Controllers } order += 2; } - logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Update, "Page Order Updated {SiteId} {ParentId}", siteid, parentid); + logger.Log(LogLevel.Information, this, LogFunction.Update, "Page Order Updated {SiteId} {ParentId}", siteid, parentid); } // DELETE api//5 @@ -93,7 +93,7 @@ namespace Oqtane.Controllers public void Delete(int id) { Pages.DeletePage(id); - logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Delete, "Page Deleted {PageId}", id); + logger.Log(LogLevel.Information, this, LogFunction.Delete, "Page Deleted {PageId}", id); } } } diff --git a/Oqtane.Server/Controllers/PageModuleController.cs b/Oqtane.Server/Controllers/PageModuleController.cs index 207bbf62..2eb6694f 100644 --- a/Oqtane.Server/Controllers/PageModuleController.cs +++ b/Oqtane.Server/Controllers/PageModuleController.cs @@ -52,7 +52,7 @@ namespace Oqtane.Controllers if (ModelState.IsValid) { PageModule = PageModules.AddPageModule(PageModule); - logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Create, "Page Module Added {PageModule}", PageModule); + logger.Log(LogLevel.Information, this, LogFunction.Create, "Page Module Added {PageModule}", PageModule); } return PageModule; } @@ -65,7 +65,7 @@ namespace Oqtane.Controllers if (ModelState.IsValid) { PageModule = PageModules.UpdatePageModule(PageModule); - logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Update, "Page Module Updated {PageModule}", PageModule); + logger.Log(LogLevel.Information, this, LogFunction.Update, "Page Module Updated {PageModule}", PageModule); } return PageModule; } @@ -86,7 +86,7 @@ namespace Oqtane.Controllers } order += 2; } - logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Update, "Page Module Order Updated {PageId} {Pane}", pageid, pane); + logger.Log(LogLevel.Information, this, LogFunction.Update, "Page Module Order Updated {PageId} {Pane}", pageid, pane); } // DELETE api//5 @@ -95,7 +95,7 @@ namespace Oqtane.Controllers public void Delete(int id) { PageModules.DeletePageModule(id); - logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Delete, "Page Module Deleted {PageModuleId}", id); + logger.Log(LogLevel.Information, this, LogFunction.Delete, "Page Module Deleted {PageModuleId}", id); } } } diff --git a/Oqtane.Server/Controllers/PermissionController.cs b/Oqtane.Server/Controllers/PermissionController.cs index cfd2849a..8cd68430 100644 --- a/Oqtane.Server/Controllers/PermissionController.cs +++ b/Oqtane.Server/Controllers/PermissionController.cs @@ -42,7 +42,7 @@ namespace Oqtane.Controllers if (ModelState.IsValid) { Permission = Permissions.AddPermission(Permission); - logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Create, "Permission Added {Permission}", Permission); + logger.Log(LogLevel.Information, this, LogFunction.Create, "Permission Added {Permission}", Permission); } return Permission; } @@ -55,7 +55,7 @@ namespace Oqtane.Controllers if (ModelState.IsValid) { Permission = Permissions.UpdatePermission(Permission); - logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Update, "Permission Updated {Permission}", Permission); + logger.Log(LogLevel.Information, this, LogFunction.Update, "Permission Updated {Permission}", Permission); } return Permission; } @@ -66,7 +66,7 @@ namespace Oqtane.Controllers public void Delete(int id) { Permissions.DeletePermission(id); - logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Delete, "Permission Deleted {PermissionId}", id); + logger.Log(LogLevel.Information, this, LogFunction.Delete, "Permission Deleted {PermissionId}", id); } } } diff --git a/Oqtane.Server/Controllers/ProfileController.cs b/Oqtane.Server/Controllers/ProfileController.cs index 4da04ab8..6b256a0b 100644 --- a/Oqtane.Server/Controllers/ProfileController.cs +++ b/Oqtane.Server/Controllers/ProfileController.cs @@ -49,7 +49,7 @@ namespace Oqtane.Controllers if (ModelState.IsValid) { Profile = Profiles.AddProfile(Profile); - logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Create, "Profile Added {Profile}", Profile); + logger.Log(LogLevel.Information, this, LogFunction.Create, "Profile Added {Profile}", Profile); } return Profile; } @@ -62,7 +62,7 @@ namespace Oqtane.Controllers if (ModelState.IsValid) { Profile = Profiles.UpdateProfile(Profile); - logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Update, "Profile Updated {Profile}", Profile); + logger.Log(LogLevel.Information, this, LogFunction.Update, "Profile Updated {Profile}", Profile); } return Profile; } @@ -73,7 +73,7 @@ namespace Oqtane.Controllers public void Delete(int id) { Profiles.DeleteProfile(id); - logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Delete, "Profile Deleted {ProfileId}", id); + logger.Log(LogLevel.Information, this, LogFunction.Delete, "Profile Deleted {ProfileId}", id); } } } diff --git a/Oqtane.Server/Controllers/RoleController.cs b/Oqtane.Server/Controllers/RoleController.cs index 358d86a8..c3bb6e45 100644 --- a/Oqtane.Server/Controllers/RoleController.cs +++ b/Oqtane.Server/Controllers/RoleController.cs @@ -49,7 +49,7 @@ namespace Oqtane.Controllers if (ModelState.IsValid) { Role = Roles.AddRole(Role); - logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Create, "Role Added {Role}", Role); + logger.Log(LogLevel.Information, this, LogFunction.Create, "Role Added {Role}", Role); } return Role; } @@ -62,7 +62,7 @@ namespace Oqtane.Controllers if (ModelState.IsValid) { Role = Roles.UpdateRole(Role); - logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Update, "Role Updated {Role}", Role); + logger.Log(LogLevel.Information, this, LogFunction.Update, "Role Updated {Role}", Role); } return Role; } @@ -73,7 +73,7 @@ namespace Oqtane.Controllers public void Delete(int id) { Roles.DeleteRole(id); - logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Delete, "Role Deleted {RoleId}", id); + logger.Log(LogLevel.Information, this, LogFunction.Delete, "Role Deleted {RoleId}", id); } } } diff --git a/Oqtane.Server/Controllers/SettingController.cs b/Oqtane.Server/Controllers/SettingController.cs index c9e85974..e55075d7 100644 --- a/Oqtane.Server/Controllers/SettingController.cs +++ b/Oqtane.Server/Controllers/SettingController.cs @@ -45,7 +45,7 @@ namespace Oqtane.Controllers if (ModelState.IsValid && IsAuthorized(Setting.EntityName, Setting.EntityId)) { Setting = Settings.AddSetting(Setting); - logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Create, "Setting Added {Setting}", Setting); + logger.Log(LogLevel.Information, this, 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.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Update, "Setting Updated {Setting}", Setting); + logger.Log(LogLevel.Information, this, LogFunction.Update, "Setting Updated {Setting}", Setting); } return Setting; } @@ -69,7 +69,7 @@ namespace Oqtane.Controllers public void Delete(int id) { Settings.DeleteSetting(id); - logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Delete, "Setting Deleted {SettingId}", id); + logger.Log(LogLevel.Information, this, LogFunction.Delete, "Setting Deleted {SettingId}", id); } private bool IsAuthorized(string EntityName, int EntityId) diff --git a/Oqtane.Server/Controllers/SiteController.cs b/Oqtane.Server/Controllers/SiteController.cs index 9fe19988..6d220188 100644 --- a/Oqtane.Server/Controllers/SiteController.cs +++ b/Oqtane.Server/Controllers/SiteController.cs @@ -67,7 +67,7 @@ namespace Oqtane.Controllers { Directory.CreateDirectory(folder); } - logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Create, "Site Added {Site}", Site); + logger.Log(LogLevel.Information, this, LogFunction.Create, "Site Added {Site}", Site); } } return Site; @@ -81,7 +81,7 @@ namespace Oqtane.Controllers if (ModelState.IsValid) { Site = Sites.UpdateSite(Site); - logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Update, "Site Updated {Site}", Site); + logger.Log(LogLevel.Information, this, LogFunction.Update, "Site Updated {Site}", Site); } return Site; } @@ -92,7 +92,7 @@ namespace Oqtane.Controllers public void Delete(int id) { Sites.DeleteSite(id); - logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Delete, "Site Deleted {SiteId}", id); + logger.Log(LogLevel.Information, this, LogFunction.Delete, "Site Deleted {SiteId}", id); } } } diff --git a/Oqtane.Server/Controllers/TenantController.cs b/Oqtane.Server/Controllers/TenantController.cs index 2c4cbc09..bf9303e9 100644 --- a/Oqtane.Server/Controllers/TenantController.cs +++ b/Oqtane.Server/Controllers/TenantController.cs @@ -44,7 +44,7 @@ namespace Oqtane.Controllers if (ModelState.IsValid) { Tenant = Tenants.AddTenant(Tenant); - logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Create, "Tenant Added {TenantId}", Tenant.TenantId); + logger.Log(LogLevel.Information, this, LogFunction.Create, "Tenant Added {TenantId}", Tenant.TenantId); } return Tenant; } @@ -57,7 +57,7 @@ namespace Oqtane.Controllers if (ModelState.IsValid) { Tenant = Tenants.UpdateTenant(Tenant); - logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Update, "Tenant Updated {TenantId}", Tenant.TenantId); + logger.Log(LogLevel.Information, this, 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.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Delete, "Tenant Deleted {TenantId}", id); + logger.Log(LogLevel.Information, this, LogFunction.Delete, "Tenant Deleted {TenantId}", id); } } } diff --git a/Oqtane.Server/Controllers/ThemeController.cs b/Oqtane.Server/Controllers/ThemeController.cs index 59baebd8..ecb9ad36 100644 --- a/Oqtane.Server/Controllers/ThemeController.cs +++ b/Oqtane.Server/Controllers/ThemeController.cs @@ -48,8 +48,8 @@ namespace Oqtane.Controllers [Authorize(Roles = Constants.HostRole)] public void InstallThemes() { - InstallationManager.InstallPackages("Themes"); - logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Create, "Themes Installed"); + InstallationManager.InstallPackages("Themes", true); + logger.Log(LogLevel.Information, this, LogFunction.Create, "Themes Installed"); } // DELETE api//xxx @@ -74,7 +74,7 @@ namespace Oqtane.Controllers { System.IO.File.Delete(file); } - logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Delete, "Theme Deleted {ThemeName}", themename); + logger.Log(LogLevel.Information, this, LogFunction.Delete, "Theme Deleted {ThemeName}", themename); InstallationManager.RestartApplication(); } diff --git a/Oqtane.Server/Controllers/UserController.cs b/Oqtane.Server/Controllers/UserController.cs index 69a11742..c8804303 100644 --- a/Oqtane.Server/Controllers/UserController.cs +++ b/Oqtane.Server/Controllers/UserController.cs @@ -127,7 +127,7 @@ namespace Oqtane.Controllers } } user.Password = ""; // remove sensitive information - logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Create, "User Added {User}", user); + logger.Log(LogLevel.Information, this, 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.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Update, "User Updated {User}", User); + logger.Log(LogLevel.Information, this, LogFunction.Update, "User Updated {User}", User); } return User; } @@ -170,7 +170,7 @@ namespace Oqtane.Controllers if (result != null) { Users.DeleteUser(id); - logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Delete, "User Deleted {UserId}", id); + logger.Log(LogLevel.Information, this, LogFunction.Delete, "User Deleted {UserId}", id); } } } @@ -193,7 +193,7 @@ namespace Oqtane.Controllers if (user != null) { user.IsAuthenticated = true; - logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Security, "User Login Successful {Username}", User.Username); + logger.Log(LogLevel.Information, this, LogFunction.Security, "User Login Successful {Username}", User.Username); if (SetCookie) { await IdentitySignInManager.SignInAsync(identityuser, IsPersistent); @@ -202,7 +202,7 @@ namespace Oqtane.Controllers } else { - logger.Log(LogLevel.Error, this.GetType().AssemblyQualifiedName, LogFunction.Security, "User Login Failed {Username}", User.Username); + logger.Log(LogLevel.Error, this, 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.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Security, "User Logout {Username}", User.Username); + logger.Log(LogLevel.Information, this, LogFunction.Security, "User Logout {Username}", User.Username); } // GET api//current diff --git a/Oqtane.Server/Controllers/UserRoleController.cs b/Oqtane.Server/Controllers/UserRoleController.cs index 7e05d02c..6d20321a 100644 --- a/Oqtane.Server/Controllers/UserRoleController.cs +++ b/Oqtane.Server/Controllers/UserRoleController.cs @@ -49,7 +49,7 @@ namespace Oqtane.Controllers if (ModelState.IsValid) { UserRole = UserRoles.AddUserRole(UserRole); - logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Create, "User Role Added {UserRole}", UserRole); + logger.Log(LogLevel.Information, this, LogFunction.Create, "User Role Added {UserRole}", UserRole); } return UserRole; } @@ -62,7 +62,7 @@ namespace Oqtane.Controllers if (ModelState.IsValid) { UserRole = UserRoles.UpdateUserRole(UserRole); - logger.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Update, "User Role Updated {UserRole}", UserRole); + logger.Log(LogLevel.Information, this, 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.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Delete, "User Role Deleted {UserRoleId}", id); + logger.Log(LogLevel.Information, this, LogFunction.Delete, "User Role Deleted {UserRoleId}", id); } } } diff --git a/Oqtane.Server/Infrastructure/IInstallationManager.cs b/Oqtane.Server/Infrastructure/IInstallationManager.cs index b608b748..8b4fdf33 100644 --- a/Oqtane.Server/Infrastructure/IInstallationManager.cs +++ b/Oqtane.Server/Infrastructure/IInstallationManager.cs @@ -2,7 +2,7 @@ { public interface IInstallationManager { - void InstallPackages(string Folders); + void InstallPackages(string Folders, bool Restart); void RestartApplication(); } } diff --git a/Oqtane.Server/Infrastructure/ILogManager.cs b/Oqtane.Server/Infrastructure/ILogManager.cs index 853e34a8..f51ee4bd 100644 --- a/Oqtane.Server/Infrastructure/ILogManager.cs +++ b/Oqtane.Server/Infrastructure/ILogManager.cs @@ -6,8 +6,8 @@ namespace Oqtane.Infrastructure { public interface ILogManager { - 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(LogLevel Level, object Class, LogFunction Function, string Message, params object[] Args); + void Log(LogLevel Level, object Class, LogFunction Function, Exception Exception, string Message, params object[] Args); void Log(Log Log); } } diff --git a/Oqtane.Server/Infrastructure/InstallationManager.cs b/Oqtane.Server/Infrastructure/InstallationManager.cs index 87ad57f5..739f1150 100644 --- a/Oqtane.Server/Infrastructure/InstallationManager.cs +++ b/Oqtane.Server/Infrastructure/InstallationManager.cs @@ -17,7 +17,7 @@ namespace Oqtane.Infrastructure this.environment = environment; } - public void InstallPackages(string Folders) + public void InstallPackages(string Folders, bool Restart) { bool install = false; string binfolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); @@ -73,7 +73,7 @@ namespace Oqtane.Infrastructure } } - if (install) + if (install && Restart) { // restart application RestartApplication(); diff --git a/Oqtane.Server/Infrastructure/LogManager.cs b/Oqtane.Server/Infrastructure/LogManager.cs index 9f8d791d..38cc4785 100644 --- a/Oqtane.Server/Infrastructure/LogManager.cs +++ b/Oqtane.Server/Infrastructure/LogManager.cs @@ -25,12 +25,12 @@ namespace Oqtane.Infrastructure this.Accessor = Accessor; } - public void Log(LogLevel Level, string Category, LogFunction Function, string Message, params object[] Args) + public void Log(LogLevel Level, object Class, LogFunction Function, string Message, params object[] Args) { - Log(Level, Category, Function, null, Message, Args); + Log(Level, Class.GetType().AssemblyQualifiedName, Function, null, Message, Args); } - public void Log(LogLevel Level, string Category, LogFunction Function, Exception Exception, string Message, params object[] Args) + public void Log(LogLevel Level, object Class, LogFunction Function, Exception Exception, string Message, params object[] Args) { Alias alias = TenantResolver.GetAlias(); Log log = new Log(); @@ -47,8 +47,15 @@ namespace Oqtane.Infrastructure log.Url = request.Scheme.ToString() + "://" + request.Host.ToString() + request.Path.ToString() + request.QueryString.ToString(); } - log.Category = Category; - log.Feature = Utilities.GetTypeNameLastSegment(Category, 0); + if (Class.GetType() != null) + { + log.Category = Class.GetType().AssemblyQualifiedName; + } + else + { + log.Category = Class.ToString(); + } + log.Feature = Utilities.GetTypeNameLastSegment(log.Category, 0); log.Function = Enum.GetName(typeof(LogFunction), Function); log.Level = Enum.GetName(typeof(LogLevel), Level); if (Exception != null) diff --git a/Oqtane.Server/Modules/HtmlText/Controllers/HtmlTextController.cs b/Oqtane.Server/Modules/HtmlText/Controllers/HtmlTextController.cs index c05d4cb8..3318d278 100644 --- a/Oqtane.Server/Modules/HtmlText/Controllers/HtmlTextController.cs +++ b/Oqtane.Server/Modules/HtmlText/Controllers/HtmlTextController.cs @@ -42,7 +42,7 @@ namespace Oqtane.Modules.HtmlText.Controllers } catch (Exception ex) { - logger.Log(LogLevel.Error, this.GetType().AssemblyQualifiedName, LogFunction.Read, ex, "Get Error {Error}", ex.Message); + logger.Log(LogLevel.Error, this, 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.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Create, "Html/Text Added {HtmlText}", HtmlText); + logger.Log(LogLevel.Information, this, LogFunction.Create, "Html/Text Added {HtmlText}", HtmlText); } return HtmlText; } catch (Exception ex) { - logger.Log(LogLevel.Error, this.GetType().AssemblyQualifiedName, LogFunction.Create, ex, "Post Error {Error}", ex.Message); + logger.Log(LogLevel.Error, this, 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.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Update, "Html/Text Updated {HtmlText}", HtmlText); + logger.Log(LogLevel.Information, this, LogFunction.Update, "Html/Text Updated {HtmlText}", HtmlText); } return HtmlText; } catch (Exception ex) { - logger.Log(LogLevel.Error, this.GetType().AssemblyQualifiedName, LogFunction.Update, ex, "Put Error {Error}", ex.Message); + logger.Log(LogLevel.Error, this, 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.Log(LogLevel.Information, this.GetType().AssemblyQualifiedName, LogFunction.Delete, "Html/Text Deleted {HtmlTextId}", id); + logger.Log(LogLevel.Information, this, LogFunction.Delete, "Html/Text Deleted {HtmlTextId}", id); } } catch (Exception ex) { - logger.Log(LogLevel.Error, this.GetType().AssemblyQualifiedName, LogFunction.Delete, ex, "Delete Error {Error}", ex.Message); + logger.Log(LogLevel.Error, this, LogFunction.Delete, ex, "Delete Error {Error}", ex.Message); throw; } } diff --git a/Oqtane.Server/Security/PermissionHandler.cs b/Oqtane.Server/Security/PermissionHandler.cs index df5a80ea..11762c21 100644 --- a/Oqtane.Server/Security/PermissionHandler.cs +++ b/Oqtane.Server/Security/PermissionHandler.cs @@ -32,7 +32,7 @@ namespace Oqtane.Security } else { - 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); + logger.Log(LogLevel.Error, this, LogFunction.Security, "User {User} Does Not Have {PermissionName} Permission For {EntityName}:{EntityId}", context.User, requirement.PermissionName, requirement.EntityName, EntityId); } } return Task.CompletedTask; diff --git a/Oqtane.Server/Startup.cs b/Oqtane.Server/Startup.cs index ce0bf948..73779d70 100644 --- a/Oqtane.Server/Startup.cs +++ b/Oqtane.Server/Startup.cs @@ -251,7 +251,7 @@ namespace Oqtane.Server } // install any modules or themes - InstallationManager.InstallPackages("Modules,Themes"); + InstallationManager.InstallPackages("Modules,Themes", false); app.UseHttpsRedirection();