structured logging

This commit is contained in:
Shaun Walker
2019-10-22 11:57:28 -04:00
parent ce25967633
commit 2e3a4efb74
79 changed files with 891 additions and 497 deletions

View File

@ -4,7 +4,7 @@ using Microsoft.AspNetCore.Authorization;
using Oqtane.Repository;
using Oqtane.Models;
using Oqtane.Shared;
using System.Linq;
using Oqtane.Infrastructure;
namespace Oqtane.Controllers
{
@ -12,10 +12,12 @@ namespace Oqtane.Controllers
public class AliasController : Controller
{
private readonly IAliasRepository Aliases;
private readonly ILogManager logger;
public AliasController(IAliasRepository Aliases)
public AliasController(IAliasRepository Aliases, ILogManager logger)
{
this.Aliases = Aliases;
this.logger = logger;
}
// GET: api/<controller>
@ -40,6 +42,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid)
{
Alias = Aliases.AddAlias(Alias);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Alias Added {Alias}", Alias);
}
return Alias;
}
@ -52,6 +55,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid)
{
Alias = Aliases.UpdateAlias(Alias);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Alias Updated {Alias}", Alias);
}
return Alias;
}
@ -62,6 +66,7 @@ namespace Oqtane.Controllers
public void Delete(int id)
{
Aliases.DeleteAlias(id);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Alias Deleted {AliasId}", id);
}
}
}

View File

@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Oqtane.Infrastructure;
using Oqtane.Shared;
using System;
using System.Collections.Generic;
@ -15,11 +16,13 @@ namespace Oqtane.Controllers
public class FileController : Controller
{
private readonly IWebHostEnvironment environment;
private readonly ILogManager logger;
private readonly string WhiteList = "jpg,jpeg,jpe,gif,bmp,png,mov,wmv,avi,mp4,mp3,doc,docx,xls,xlsx,ppt,pptx,pdf,txt,zip,nupkg";
public FileController(IWebHostEnvironment environment)
public FileController(IWebHostEnvironment environment, ILogManager logger)
{
this.environment = environment;
this.logger = logger;
}
// GET: api/<controller>?folder=x
@ -107,6 +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));
}
}
}
@ -169,6 +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);
}
}

View File

@ -0,0 +1,39 @@
using Microsoft.AspNetCore.Mvc;
using Oqtane.Models;
using System.Collections.Generic;
using Oqtane.Repository;
using Oqtane.Infrastructure;
namespace Oqtane.Controllers
{
[Route("{site}/api/[controller]")]
public class LogController : Controller
{
private readonly ILogManager Logger;
private readonly ILogRepository Logs;
public LogController(ILogManager Logger, ILogRepository Logs)
{
this.Logger = Logger;
this.Logs = Logs;
}
// GET: api/<controller>?siteid=x
[HttpGet]
public IEnumerable<Log> Get(string siteid)
{
return Logs.GetLogs(int.Parse(siteid));
}
// POST api/<controller>
[HttpPost]
public void Post([FromBody] Log Log)
{
if (ModelState.IsValid)
{
Logger.AddLog(Log);
}
}
}
}

View File

@ -10,6 +10,7 @@ using System;
using Oqtane.Modules;
using Microsoft.Extensions.DependencyInjection;
using System.Text.Json;
using Oqtane.Infrastructure;
namespace Oqtane.Controllers
{
@ -20,13 +21,15 @@ namespace Oqtane.Controllers
private readonly IPageModuleRepository PageModules;
private readonly IModuleDefinitionRepository ModuleDefinitions;
private readonly IServiceProvider ServiceProvider;
private readonly ILogManager logger;
public ModuleController(IModuleRepository Modules, IPageModuleRepository PageModules, IModuleDefinitionRepository ModuleDefinitions, IServiceProvider ServiceProvider)
public ModuleController(IModuleRepository Modules, IPageModuleRepository PageModules, IModuleDefinitionRepository ModuleDefinitions, IServiceProvider ServiceProvider, ILogManager logger)
{
this.Modules = Modules;
this.PageModules = PageModules;
this.ModuleDefinitions = ModuleDefinitions;
this.ServiceProvider = ServiceProvider;
this.logger = logger;
}
// GET: api/<controller>?siteid=x
@ -73,6 +76,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid)
{
Module = Modules.AddModule(Module);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Module Added {Module}", Module);
}
return Module;
}
@ -85,6 +89,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid)
{
Module = Modules.UpdateModule(Module);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Module Updated {Module}", Module);
}
return Module;
}
@ -95,6 +100,7 @@ namespace Oqtane.Controllers
public void Delete(int id)
{
Modules.DeleteModule(id);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Module Deleted {ModuleId}", id);
}
// GET api/<controller>/export?moduleid=x
@ -135,6 +141,7 @@ namespace Oqtane.Controllers
}
}
content = JsonSerializer.Serialize(modulecontent);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Module Content Exported {ModuleId}", moduleid);
}
}
}
@ -180,6 +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);
}
}
}

View File

@ -18,12 +18,14 @@ namespace Oqtane.Controllers
private readonly IModuleDefinitionRepository ModuleDefinitions;
private readonly IInstallationManager InstallationManager;
private readonly IWebHostEnvironment environment;
private readonly ILogManager logger;
public ModuleDefinitionController(IModuleDefinitionRepository ModuleDefinitions, IInstallationManager InstallationManager, IWebHostEnvironment environment)
public ModuleDefinitionController(IModuleDefinitionRepository ModuleDefinitions, IInstallationManager InstallationManager, IWebHostEnvironment environment, ILogManager logger)
{
this.ModuleDefinitions = ModuleDefinitions;
this.InstallationManager = InstallationManager;
this.environment = environment;
this.logger = logger;
}
// GET: api/<controller>?siteid=x
@ -50,6 +52,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid)
{
ModuleDefinitions.UpdateModuleDefinition(ModuleDefinition);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Module Definition Updated {ModuleDefinition}", ModuleDefinition);
}
}
@ -58,6 +61,7 @@ namespace Oqtane.Controllers
public void InstallModules()
{
InstallationManager.InstallPackages("Modules");
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Modules Installed");
}
// DELETE api/<controller>/5?siteid=x
@ -84,6 +88,7 @@ namespace Oqtane.Controllers
}
ModuleDefinitions.DeleteModuleDefinition(id, siteid);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Module Deleted {ModuleDefinitionId}", id);
InstallationManager.RestartApplication();
}

View File

@ -5,6 +5,7 @@ using Oqtane.Repository;
using Oqtane.Models;
using Oqtane.Shared;
using System.Linq;
using Oqtane.Infrastructure;
namespace Oqtane.Controllers
{
@ -12,10 +13,12 @@ namespace Oqtane.Controllers
public class PageController : Controller
{
private readonly IPageRepository Pages;
private readonly ILogManager logger;
public PageController(IPageRepository Pages)
public PageController(IPageRepository Pages, ILogManager logger)
{
this.Pages = Pages;
this.logger = logger;
}
// GET: api/<controller>?siteid=x
@ -47,6 +50,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid)
{
Page = Pages.AddPage(Page);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Page Added {Page}", Page);
}
return Page;
}
@ -59,6 +63,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid)
{
Page = Pages.UpdatePage(Page);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Page Updated {Page}", Page);
}
return Page;
}
@ -79,6 +84,7 @@ namespace Oqtane.Controllers
}
order += 2;
}
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Page Order Updated {SiteId} {ParentId}", siteid, parentid);
}
// DELETE api/<controller>/5
@ -87,6 +93,7 @@ namespace Oqtane.Controllers
public void Delete(int id)
{
Pages.DeletePage(id);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Page Deleted {PageId}", id);
}
}
}

View File

@ -5,6 +5,7 @@ using Oqtane.Repository;
using Oqtane.Models;
using Oqtane.Shared;
using System.Linq;
using Oqtane.Infrastructure;
namespace Oqtane.Controllers
{
@ -13,11 +14,13 @@ namespace Oqtane.Controllers
{
private readonly IPageModuleRepository PageModules;
private readonly IModuleRepository Modules;
private readonly ILogManager logger;
public PageModuleController(IPageModuleRepository PageModules, IModuleRepository Modules)
public PageModuleController(IPageModuleRepository PageModules, IModuleRepository Modules, ILogManager logger)
{
this.PageModules = PageModules;
this.Modules = Modules;
this.logger = logger;
}
// GET: api/<controller>
@ -42,6 +45,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid)
{
PageModule = PageModules.AddPageModule(PageModule);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Page Module Added {PageModule}", PageModule);
}
return PageModule;
}
@ -54,6 +58,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid)
{
PageModule = PageModules.UpdatePageModule(PageModule);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Page Module Updated {PageModule}", PageModule);
}
return PageModule;
}
@ -74,6 +79,7 @@ namespace Oqtane.Controllers
}
order += 2;
}
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Page Module Order Updated {PageId} {Pane}", pageid, pane);
}
// DELETE api/<controller>/5
@ -82,6 +88,7 @@ namespace Oqtane.Controllers
public void Delete(int id)
{
PageModules.DeletePageModule(id);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Page Module Deleted {PageModuleId}", id);
}
}
}

View File

@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Authorization;
using Oqtane.Repository;
using Oqtane.Models;
using Oqtane.Shared;
using Oqtane.Infrastructure;
namespace Oqtane.Controllers
{
@ -11,10 +12,12 @@ namespace Oqtane.Controllers
public class PermissionController : Controller
{
private readonly IPermissionRepository Permissions;
private readonly ILogManager logger;
public PermissionController(IPermissionRepository Permissions)
public PermissionController(IPermissionRepository Permissions, ILogManager logger)
{
this.Permissions = Permissions;
this.logger = logger;
}
// GET: api/<controller>
@ -39,6 +42,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid)
{
Permission = Permissions.AddPermission(Permission);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Permission Added {Permission}", Permission);
}
return Permission;
}
@ -51,6 +55,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid)
{
Permission = Permissions.UpdatePermission(Permission);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Permission Updated {Permission}", Permission);
}
return Permission;
}
@ -61,6 +66,7 @@ namespace Oqtane.Controllers
public void Delete(int id)
{
Permissions.DeletePermission(id);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Permission Deleted {PermissionId}", id);
}
}
}

View File

@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Authorization;
using Oqtane.Repository;
using Oqtane.Models;
using Oqtane.Shared;
using Oqtane.Infrastructure;
namespace Oqtane.Controllers
{
@ -11,10 +12,12 @@ namespace Oqtane.Controllers
public class ProfileController : Controller
{
private readonly IProfileRepository Profiles;
private readonly ILogManager logger;
public ProfileController(IProfileRepository Profiles)
public ProfileController(IProfileRepository Profiles, ILogManager logger)
{
this.Profiles = Profiles;
this.logger = logger;
}
// GET: api/<controller>?siteid=x
@ -46,6 +49,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid)
{
Profile = Profiles.AddProfile(Profile);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Profile Added {Profile}", Profile);
}
return Profile;
}
@ -58,6 +62,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid)
{
Profile = Profiles.UpdateProfile(Profile);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Profile Updated {Profile}", Profile);
}
return Profile;
}
@ -68,6 +73,7 @@ namespace Oqtane.Controllers
public void Delete(int id)
{
Profiles.DeleteProfile(id);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Profile Deleted {ProfileId}", id);
}
}
}

View File

@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Authorization;
using Oqtane.Repository;
using Oqtane.Models;
using Oqtane.Shared;
using Oqtane.Infrastructure;
namespace Oqtane.Controllers
{
@ -11,10 +12,12 @@ namespace Oqtane.Controllers
public class RoleController : Controller
{
private readonly IRoleRepository Roles;
private readonly ILogManager logger;
public RoleController(IRoleRepository Roles)
public RoleController(IRoleRepository Roles, ILogManager logger)
{
this.Roles = Roles;
this.logger = logger;
}
// GET: api/<controller>?siteid=x
@ -46,6 +49,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid)
{
Role = Roles.AddRole(Role);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Role Added {Role}", Role);
}
return Role;
}
@ -58,6 +62,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid)
{
Role = Roles.UpdateRole(Role);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Role Updated {Role}", Role);
}
return Role;
}
@ -68,6 +73,7 @@ namespace Oqtane.Controllers
public void Delete(int id)
{
Roles.DeleteRole(id);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Role Deleted {RoleId}", id);
}
}
}

View File

@ -5,6 +5,7 @@ using Oqtane.Repository;
using Oqtane.Models;
using Oqtane.Shared;
using Oqtane.Security;
using Oqtane.Infrastructure;
namespace Oqtane.Controllers
{
@ -13,11 +14,13 @@ namespace Oqtane.Controllers
{
private readonly ISettingRepository Settings;
private readonly IUserPermissions UserPermissions;
private readonly ILogManager logger;
public SettingController(ISettingRepository Settings, IUserPermissions UserPermissions)
public SettingController(ISettingRepository Settings, IUserPermissions UserPermissions, ILogManager logger)
{
this.Settings = Settings;
this.UserPermissions = UserPermissions;
this.logger = logger;
}
// GET: api/<controller>
@ -42,6 +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);
}
return Setting;
}
@ -54,6 +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);
}
return Setting;
}
@ -64,6 +69,7 @@ namespace Oqtane.Controllers
public void Delete(int id)
{
Settings.DeleteSetting(id);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Setting Deleted {SettingId}", id);
}
private bool IsAuthorized(string EntityName, int EntityId)

View File

@ -7,6 +7,7 @@ using Oqtane.Shared;
using System.Linq;
using System.IO;
using Microsoft.AspNetCore.Hosting;
using Oqtane.Infrastructure;
namespace Oqtane.Controllers
{
@ -16,12 +17,14 @@ namespace Oqtane.Controllers
private readonly ISiteRepository Sites;
private readonly ITenantResolver Tenants;
private readonly IWebHostEnvironment environment;
private readonly ILogManager logger;
public SiteController(ISiteRepository Sites, ITenantResolver Tenants, IWebHostEnvironment environment)
public SiteController(ISiteRepository Sites, ITenantResolver Tenants, IWebHostEnvironment environment, ILogManager logger)
{
this.Sites = Sites;
this.Tenants = Tenants;
this.environment = environment;
this.logger = logger;
}
// GET: api/<controller>
@ -61,6 +64,7 @@ namespace Oqtane.Controllers
{
Directory.CreateDirectory(folder);
}
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Site Added {Site}", Site);
}
}
return Site;
@ -74,6 +78,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid)
{
Site = Sites.UpdateSite(Site);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Site Updated {Site}", Site);
}
return Site;
}
@ -84,6 +89,7 @@ namespace Oqtane.Controllers
public void Delete(int id)
{
Sites.DeleteSite(id);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Site Deleted {SiteId}", id);
}
}
}

View File

@ -4,6 +4,7 @@ using Oqtane.Repository;
using Oqtane.Models;
using System.Collections.Generic;
using Oqtane.Shared;
using Oqtane.Infrastructure;
namespace Oqtane.Controllers
{
@ -11,10 +12,12 @@ namespace Oqtane.Controllers
public class TenantController : Controller
{
private readonly ITenantRepository Tenants;
private readonly ILogManager logger;
public TenantController(ITenantRepository Tenants)
public TenantController(ITenantRepository Tenants, ILogManager logger)
{
this.Tenants = Tenants;
this.logger = logger;
}
// GET: api/<controller>
@ -39,6 +42,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid)
{
Tenant = Tenants.AddTenant(Tenant);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Tenant Added {TenantId}", Tenant.TenantId);
}
return Tenant;
}
@ -51,6 +55,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid)
{
Tenant = Tenants.UpdateTenant(Tenant);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Tenant Updated {TenantId}", Tenant.TenantId);
}
return Tenant;
}
@ -61,6 +66,7 @@ namespace Oqtane.Controllers
public void Delete(int id)
{
Tenants.DeleteTenant(id);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Tenant Deleted {TenantId}", id);
}
}
}

View File

@ -18,12 +18,14 @@ namespace Oqtane.Controllers
private readonly IThemeRepository Themes;
private readonly IInstallationManager InstallationManager;
private readonly IWebHostEnvironment environment;
private readonly ILogManager logger;
public ThemeController(IThemeRepository Themes, IInstallationManager InstallationManager, IWebHostEnvironment environment)
public ThemeController(IThemeRepository Themes, IInstallationManager InstallationManager, IWebHostEnvironment environment, ILogManager logger)
{
this.Themes = Themes;
this.InstallationManager = InstallationManager;
this.environment = environment;
this.logger = logger;
}
// GET: api/<controller>
@ -47,6 +49,7 @@ namespace Oqtane.Controllers
public void InstallThemes()
{
InstallationManager.InstallPackages("Themes");
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Themes Installed");
}
// DELETE api/<controller>/xxx
@ -71,6 +74,7 @@ namespace Oqtane.Controllers
{
System.IO.File.Delete(file);
}
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Theme Deleted {ThemeName}", themename);
InstallationManager.RestartApplication();
}

View File

@ -9,6 +9,7 @@ using System.Threading.Tasks;
using System.Linq;
using System.Security.Claims;
using Oqtane.Shared;
using Oqtane.Infrastructure;
namespace Oqtane.Controllers
{
@ -20,14 +21,16 @@ namespace Oqtane.Controllers
private readonly IUserRoleRepository UserRoles;
private readonly UserManager<IdentityUser> IdentityUserManager;
private readonly SignInManager<IdentityUser> IdentitySignInManager;
private readonly ILogManager logger;
public UserController(IUserRepository Users, IRoleRepository Roles, IUserRoleRepository UserRoles, UserManager<IdentityUser> IdentityUserManager, SignInManager<IdentityUser> IdentitySignInManager)
public UserController(IUserRepository Users, IRoleRepository Roles, IUserRoleRepository UserRoles, UserManager<IdentityUser> IdentityUserManager, SignInManager<IdentityUser> IdentitySignInManager, ILogManager logger)
{
this.Users = Users;
this.Roles = Roles;
this.UserRoles = UserRoles;
this.IdentityUserManager = IdentityUserManager;
this.IdentitySignInManager = IdentitySignInManager;
this.logger = logger;
}
// GET: api/<controller>?siteid=x
@ -123,6 +126,8 @@ namespace Oqtane.Controllers
UserRoles.AddUserRole(userrole);
}
}
user.Password = ""; // remove sensitive information
logger.AddLog(this.GetType().FullName, LogLevel.Information, "User Added {User}", user);
}
return user;
@ -145,6 +150,8 @@ namespace Oqtane.Controllers
}
}
User = Users.UpdateUser(User);
User.Password = ""; // remove sensitive information
logger.AddLog(this.GetType().FullName, LogLevel.Information, "User Updated {User}", User);
}
return User;
}
@ -163,6 +170,7 @@ namespace Oqtane.Controllers
if (result != null)
{
Users.DeleteUser(id);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "User Deleted {UserId}", id);
}
}
}
@ -185,12 +193,17 @@ namespace Oqtane.Controllers
if (user != null)
{
user.IsAuthenticated = true;
logger.AddLog(this.GetType().FullName, LogLevel.Information, "User Login Successful {Username}", User.Username);
if (SetCookie)
{
await IdentitySignInManager.SignInAsync(identityuser, IsPersistent);
}
}
}
else
{
logger.AddLog(this.GetType().FullName, LogLevel.Error, "User Login Failed {Username}", User.Username);
}
}
}
@ -203,6 +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);
}
// GET api/<controller>/current

View File

@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Authorization;
using Oqtane.Repository;
using Oqtane.Models;
using Oqtane.Shared;
using Oqtane.Infrastructure;
namespace Oqtane.Controllers
{
@ -11,10 +12,12 @@ namespace Oqtane.Controllers
public class UserRoleController : Controller
{
private readonly IUserRoleRepository UserRoles;
private readonly ILogManager logger;
public UserRoleController(IUserRoleRepository UserRoles)
public UserRoleController(IUserRoleRepository UserRoles, ILogManager logger)
{
this.UserRoles = UserRoles;
this.logger = logger;
}
// GET: api/<controller>?userid=x
@ -46,6 +49,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid)
{
UserRole = UserRoles.AddUserRole(UserRole);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "User Role Added {UserRole}", UserRole);
}
return UserRole;
}
@ -58,6 +62,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid)
{
UserRole = UserRoles.UpdateUserRole(UserRole);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "User Role Updated {UserRole}", UserRole);
}
return UserRole;
}
@ -68,6 +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);
}
}
}

View File

@ -0,0 +1,13 @@
using Oqtane.Models;
using Oqtane.Shared;
using System;
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);
}
}

View File

@ -0,0 +1,128 @@
using Oqtane.Shared;
using System;
using Oqtane.Models;
using System.Text.Json;
using Oqtane.Repository;
using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore.Http;
using System.Security.Claims;
using System.Collections.Generic;
namespace Oqtane.Infrastructure
{
public class LogManager : ILogManager
{
private readonly ILogRepository Logs;
private readonly ITenantResolver TenantResolver;
private readonly IConfigurationRoot Config;
private readonly IHttpContextAccessor Accessor;
public LogManager(ILogRepository Logs, ITenantResolver TenantResolver, IConfigurationRoot Config, IHttpContextAccessor Accessor)
{
this.Logs = Logs;
this.TenantResolver = TenantResolver;
this.Config = Config;
this.Accessor = Accessor;
}
public void AddLog(string Category, LogLevel Level, string Message, params object[] Args)
{
AddLog(Category, Level, null, Message, Args);
}
public void AddLog(string Category, LogLevel Level, Exception Exception, string Message, params object[] Args)
{
Alias alias = TenantResolver.GetAlias();
Log log = new Log();
log.SiteId = alias.SiteId;
log.PageId = null;
log.ModuleId = null;
if (Accessor.HttpContext.User.FindFirst(ClaimTypes.PrimarySid) != null)
{
log.UserId = int.Parse(Accessor.HttpContext.User.FindFirst(ClaimTypes.PrimarySid).Value);
}
HttpRequest request = Accessor.HttpContext.Request;
if (request != null)
{
log.Url = request.Scheme.ToString() + "://" + request.Host.ToString() + request.Path.ToString() + request.QueryString.ToString();
}
log.Category = Category;
log.Level = Enum.GetName(typeof(LogLevel), Level);
if (Exception != null)
{
log.Exception = JsonSerializer.Serialize(Exception);
}
log.Message = Message;
log.MessageTemplate = "";
log.Properties = JsonSerializer.Serialize(Args);
AddLog(log);
}
public void AddLog(Log Log)
{
LogLevel minlevel = LogLevel.Information;
var section = Config.GetSection("Logging:LogLevel:Default");
if (section.Exists())
{
minlevel = Enum.Parse<LogLevel>(Config.GetSection("Logging:LogLevel:Default").ToString());
}
if (Enum.Parse<LogLevel>(Log.Level) >= minlevel)
{
Log.LogDate = DateTime.UtcNow;
Log.Server = Environment.MachineName;
Log.MessageTemplate = Log.Message;
Log = ProcessStructuredLog(Log);
Logs.AddLog(Log);
}
}
private Log ProcessStructuredLog(Log Log)
{
string message = Log.Message;
string properties = "";
if (!string.IsNullOrEmpty(message) && message.Contains("{") && message.Contains("}") && !string.IsNullOrEmpty(Log.Properties))
{
// get the named holes in the message and replace values
object[] values = JsonSerializer.Deserialize<object[]>(Log.Properties);
List<string> names = new List<string>();
int index = message.IndexOf("{");
while (index != -1)
{
if (message.IndexOf("}", index) != -1)
{
names.Add(message.Substring(index + 1, message.IndexOf("}", index) - index - 1));
if (values.Length > (names.Count - 1))
{
message = message.Replace("{" + names[names.Count - 1] + "}", values[names.Count - 1].ToString());
}
}
index = message.IndexOf("{", index + 1);
}
// rebuild properties into dictionary
Dictionary<string, string> propertydictionary = new Dictionary<string, string>();
for (int i = 0; i < values.Length; i++)
{
string value = "";
if (values[i] != null)
{
value = values[i].ToString();
}
if (i < names.Count)
{
propertydictionary.Add(names[i], value);
}
else
{
propertydictionary.Add("Property" + i.ToString(), value);
}
}
properties = JsonSerializer.Serialize(propertydictionary);
}
Log.Message = message;
Log.Properties = properties;
return Log;
}
}
}

View File

@ -1,36 +0,0 @@
using System;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
namespace Oqtane.Logging
{
static public class DBLoggerExtensions
{
static public ILoggingBuilder AddDBLogger(this ILoggingBuilder builder)
{
builder.AddConfiguration();
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<ILoggerProvider, DBLoggerProvider>());
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<IConfigureOptions<DBLoggerOptions>, DBLoggerOptionsSetup>());
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<IOptionsChangeTokenSource<DBLoggerOptions>, LoggerProviderOptionsChangeTokenSource<DBLoggerOptions, DBLoggerProvider>>());
return builder;
}
static public ILoggingBuilder AddDBLogger(this ILoggingBuilder builder, Action<DBLoggerOptions> configure)
{
if (configure == null)
{
throw new ArgumentNullException(nameof(configure));
}
builder.AddDBLogger();
builder.Services.Configure(configure);
return builder;
}
}
}

View File

@ -1,13 +0,0 @@
using Microsoft.Extensions.Logging;
namespace Oqtane.Logging
{
public class DBLoggerOptions
{
public DBLoggerOptions()
{
}
public LogLevel LogLevel { get; set; } = LogLevel.Information;
}
}

View File

@ -1,11 +0,0 @@
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Logging.Configuration;
namespace Oqtane.Logging
{
internal class DBLoggerOptionsSetup : ConfigureFromConfigurationOptions<DBLoggerOptions>
{
public DBLoggerOptionsSetup(ILoggerProviderConfiguration<DBLoggerProvider> providerConfiguration)
: base(providerConfiguration.Configuration) {}
}
}

View File

@ -1,94 +0,0 @@
using System;
using System.Threading.Tasks;
using System.Collections.Concurrent;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Logging;
using Oqtane.Models;
using Oqtane.Repository;
namespace Oqtane.Logging
{
[Microsoft.Extensions.Logging.ProviderAlias("DB")]
public class DBLoggerProvider : LoggerProvider
{
bool Terminated;
ConcurrentQueue<LogEntry> LogQueue = new ConcurrentQueue<LogEntry>();
private Tenant tenant;
internal DBLoggerOptions Settings { get; private set; }
public DBLoggerProvider(ITenantResolver TenantResolver)
{
tenant = TenantResolver.GetTenant();
}
public override void WriteLog(LogEntry LogEntry)
{
// enrich with tenant information
LogQueue.Enqueue(LogEntry);
}
void ThreadProc()
{
Task.Run(() => {
while (!Terminated)
{
try
{
AddLogEntry();
System.Threading.Thread.Sleep(100);
}
catch
{
}
}
});
}
void AddLogEntry()
{
// check the LogQueue.Count to determine if a threshold has been reached
// then dequeue the items into temp storage based on TenantId and bulk insert them into the database
LogEntry logentry = null;
if (LogQueue.TryDequeue(out logentry))
{
// convert logentry object to object which can be stored in database
}
}
protected override void Dispose(bool Disposing)
{
Terminated = true;
base.Dispose(Disposing);
}
public DBLoggerProvider(IOptionsMonitor<DBLoggerOptions> Settings)
: this(Settings.CurrentValue)
{
SettingsChangeToken = Settings.OnChange(settings => {
this.Settings = settings;
});
}
public DBLoggerProvider(DBLoggerOptions Settings)
{
this.Settings = Settings;
ThreadProc();
}
public override bool IsEnabled(LogLevel LogLevel)
{
bool Result = LogLevel != LogLevel.None
&& this.Settings.LogLevel != LogLevel.None
&& Convert.ToInt32(LogLevel) >= Convert.ToInt32(this.Settings.LogLevel);
return Result;
}
}
}

View File

@ -1,32 +0,0 @@
using Microsoft.Extensions.Logging;
using Oqtane.Models;
using Oqtane.Repository;
using System;
using System.Collections.Generic;
namespace Oqtane.Logging
{
public class LogEntry
{
public LogEntry()
{
TimeStampUtc = DateTime.UtcNow;
UserName = Environment.UserName;
}
static public readonly string StaticHostName = System.Net.Dns.GetHostName();
public string UserName { get; private set; }
public string HostName { get { return StaticHostName; } }
public DateTime TimeStampUtc { get; private set; }
public string Category { get; set; }
public LogLevel Level { get; set; }
public string Text { get; set; }
public Exception Exception { get; set; }
public EventId EventId { get; set; }
public object State { get; set; }
public string StateText { get; set; }
public Dictionary<string, object> StateProperties { get; set; }
public List<LogScope> Scopes { get; set; }
}
}

View File

@ -1,10 +0,0 @@
using System.Collections.Generic;
namespace Oqtane.Logging
{
public class LogScope
{
public string Text { get; set; }
public Dictionary<string, object> Properties { get; set; }
}
}

View File

@ -1,91 +0,0 @@
using System;
using System.Collections.Generic;
using Microsoft.Extensions.Logging;
namespace Oqtane.Logging
{
internal class Logger : ILogger
{
public LoggerProvider Provider { get; private set; }
public string Category { get; private set; }
public Logger(LoggerProvider Provider, string Category)
{
this.Provider = Provider;
this.Category = Category;
}
IDisposable ILogger.BeginScope<TState>(TState State)
{
return Provider.ScopeProvider.Push(State);
}
bool ILogger.IsEnabled(LogLevel LogLevel)
{
return Provider.IsEnabled(LogLevel);
}
void ILogger.Log<TState>(LogLevel LogLevel, EventId EventId, TState State, Exception Exception, Func<TState, Exception, string> Formatter)
{
if ((this as ILogger).IsEnabled(LogLevel))
{
LogEntry logentry = new LogEntry();
// we need the TenantId and SiteId
logentry.Category = this.Category;
logentry.Level = LogLevel;
logentry.Text = Exception?.Message ?? State.ToString();
logentry.Exception = Exception;
logentry.EventId = EventId;
logentry.State = State;
if (State is string)
{
logentry.StateText = State.ToString();
}
else if (State is IEnumerable<KeyValuePair<string, object>> Properties)
{
logentry.StateProperties = new Dictionary<string, object>();
foreach (KeyValuePair<string, object> item in Properties)
{
logentry.StateProperties[item.Key] = item.Value;
}
}
if (Provider.ScopeProvider != null)
{
Provider.ScopeProvider.ForEachScope((value, loggingProps) =>
{
if (logentry.Scopes == null)
{
logentry.Scopes = new List<LogScope>();
}
LogScope Scope = new LogScope();
logentry.Scopes.Add(Scope);
if (value is string)
{
Scope.Text = value.ToString();
}
else if (value is IEnumerable<KeyValuePair<string, object>> props)
{
if (Scope.Properties == null)
Scope.Properties = new Dictionary<string, object>();
foreach (var pair in props)
{
Scope.Properties[pair.Key] = pair.Value;
}
}
}, State);
}
Provider.WriteLog(logentry);
}
}
}
}

View File

@ -1,80 +0,0 @@
using System;
using System.Collections.Concurrent;
using Microsoft.Extensions.Logging;
namespace Oqtane.Logging
{
public abstract class LoggerProvider : IDisposable, ILoggerProvider, ISupportExternalScope
{
ConcurrentDictionary<string, Logger> loggers = new ConcurrentDictionary<string, Logger>();
IExternalScopeProvider fScopeProvider;
protected IDisposable SettingsChangeToken;
void ISupportExternalScope.SetScopeProvider(IExternalScopeProvider ScopeProvider)
{
fScopeProvider = ScopeProvider;
}
ILogger ILoggerProvider.CreateLogger(string Category)
{
return loggers.GetOrAdd(Category,
(category) => {
return new Logger(this, category);
});
}
void IDisposable.Dispose()
{
if (!this.IsDisposed)
{
try
{
Dispose(true);
}
catch
{
}
this.IsDisposed = true;
GC.SuppressFinalize(this);
}
}
protected virtual void Dispose(bool Disposing)
{
if (SettingsChangeToken != null)
{
SettingsChangeToken.Dispose();
SettingsChangeToken = null;
}
}
public LoggerProvider()
{
}
~LoggerProvider()
{
if (!this.IsDisposed)
{
Dispose(false);
}
}
public abstract bool IsEnabled(LogLevel LogLevel);
public abstract void WriteLog(LogEntry LogEntry);
internal IExternalScopeProvider ScopeProvider
{
get
{
if (fScopeProvider == null)
fScopeProvider = new LoggerExternalScopeProvider();
return fScopeProvider;
}
}
public bool IsDisposed { get; protected set; }
}
}

View File

@ -3,18 +3,22 @@ using Microsoft.AspNetCore.Authorization;
using Oqtane.Modules.HtmlText.Models;
using Oqtane.Modules.HtmlText.Repository;
using Microsoft.AspNetCore.Http;
using Oqtane.Infrastructure;
using Oqtane.Shared;
namespace Oqtane.Modules.HtmlText.Controllers
{
[Route("{site}/api/[controller]")]
public class HtmlTextController : Controller
{
private IHtmlTextRepository htmltext;
private readonly IHtmlTextRepository htmltext;
private readonly ILogManager logger;
private int EntityId = -1; // passed as a querystring parameter for authorization and used for validation
public HtmlTextController(IHtmlTextRepository HtmlText, IHttpContextAccessor HttpContextAccessor)
public HtmlTextController(IHtmlTextRepository HtmlText, ILogManager logger, IHttpContextAccessor HttpContextAccessor)
{
htmltext = HtmlText;
this.logger = logger;
if (HttpContextAccessor.HttpContext.Request.Query.ContainsKey("entityid"))
{
EntityId = int.Parse(HttpContextAccessor.HttpContext.Request.Query["entityid"]);
@ -42,6 +46,7 @@ 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);
}
return HtmlText;
}
@ -54,6 +59,7 @@ 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);
}
return HtmlText;
}
@ -66,6 +72,7 @@ namespace Oqtane.Modules.HtmlText.Controllers
if (id == EntityId)
{
htmltext.DeleteHtmlText(id);
logger.AddLog(this.GetType().FullName, LogLevel.Information, "Html/Text Deleted {HtmlTextId}", id);
}
}
}

View File

@ -1,7 +1,6 @@
using Microsoft.EntityFrameworkCore;
using Oqtane.Modules.HtmlText.Models;
using Oqtane.Repository;
using Oqtane.Modules;
using Microsoft.AspNetCore.Http;
namespace Oqtane.Modules.HtmlText.Repository

View File

@ -1,8 +1,6 @@
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using Oqtane.Modules.HtmlText.Models;
using Oqtane.Modules;
namespace Oqtane.Modules.HtmlText.Repository
{

View File

@ -43,7 +43,6 @@
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.0-preview1.19506.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0-rc3" />
</ItemGroup>

View File

@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Microsoft.AspNetCore.Blazor.Hosting;
// used by client-side Blazor
using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore;

View File

@ -16,6 +16,7 @@ namespace Oqtane.Repository
public virtual DbSet<UserRole> UserRole { get; set; }
public virtual DbSet<Permission> Permission { get; set; }
public virtual DbSet<Setting> Setting { get; set; }
public virtual DbSet<Log> Log { get; set; }
public TenantDBContext(ITenantResolver TenantResolver, IHttpContextAccessor accessor) : base(TenantResolver, accessor)
{

View File

@ -0,0 +1,11 @@
using Oqtane.Models;
using System.Collections.Generic;
namespace Oqtane.Repository
{
public interface ILogRepository
{
void AddLog(Log Log);
IEnumerable<Log> GetLogs(int SiteId);
}
}

View File

@ -0,0 +1,28 @@
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using Oqtane.Models;
namespace Oqtane.Repository
{
public class LogRepository : ILogRepository
{
private TenantDBContext db;
public LogRepository(TenantDBContext context)
{
db = context;
}
public void AddLog(Log Log)
{
db.Log.Add(Log);
db.SaveChanges();
}
public IEnumerable<Log> GetLogs(int SiteId)
{
return db.Log.Where(item => item.SiteId == SiteId).OrderByDescending(item=> item.LogDate).Take(50);
}
}
}

View File

@ -68,6 +68,9 @@ namespace Oqtane.Repository
SiteTemplate.Add(new PageTemplate { Name = "Role Management", Parent = "Admin", Path = "admin/roles", Icon = "lock-locked", IsNavigation = false, EditMode = true, PagePermissions = "[{\"PermissionName\":\"View\",\"Permissions\":\"Administrators\"},{\"PermissionName\":\"Edit\",\"Permissions\":\"Administrators\"}]", PageTemplateModules = new List<PageTemplateModule> {
new PageTemplateModule { ModuleDefinitionName = "Oqtane.Modules.Admin.Roles, Oqtane.Client", Title = "Role Management", Pane = "Content", ModulePermissions = "[{\"PermissionName\":\"View\",\"Permissions\":\"Administrators\"},{\"PermissionName\":\"Edit\",\"Permissions\":\"Administrators\"}]", Content = "" }
}});
SiteTemplate.Add(new PageTemplate { Name = "Event Log", Parent = "Admin", Path = "admin/log", Icon = "magnifying-glass", IsNavigation = false, EditMode = true, PagePermissions = "[{\"PermissionName\":\"View\",\"Permissions\":\"Administrators\"},{\"PermissionName\":\"Edit\",\"Permissions\":\"Administrators\"}]", PageTemplateModules = new List<PageTemplateModule> {
new PageTemplateModule { ModuleDefinitionName = "Oqtane.Modules.Admin.Logs, Oqtane.Client", Title = "Event Log", Pane = "Content", ModulePermissions = "[{\"PermissionName\":\"View\",\"Permissions\":\"Administrators\"},{\"PermissionName\":\"Edit\",\"Permissions\":\"Administrators\"}]", Content = "" }
}});
SiteTemplate.Add(new PageTemplate { Name = "Tenant Management", Parent = "Admin", Path = "admin/tenants", Icon = "list", IsNavigation = false, EditMode = true, PagePermissions = "[{\"PermissionName\":\"View\",\"Permissions\":\"Administrators\"},{\"PermissionName\":\"Edit\",\"Permissions\":\"Administrators\"}]", PageTemplateModules = new List<PageTemplateModule> {
new PageTemplateModule { ModuleDefinitionName = "Oqtane.Modules.Admin.Tenants, Oqtane.Client", Title = "Tenant Management", Pane = "Content", ModulePermissions = "[{\"PermissionName\":\"View\",\"Permissions\":\"Administrators\"},{\"PermissionName\":\"Edit\",\"Permissions\":\"Administrators\"}]", Content = "" }
}});
@ -80,8 +83,8 @@ namespace Oqtane.Repository
SiteTemplate.Add(new PageTemplate { Name = "Upgrade Service", Parent = "Admin", Path = "admin/upgrade", Icon = "aperture", IsNavigation = false, EditMode = true, PagePermissions = "[{\"PermissionName\":\"View\",\"Permissions\":\"Administrators\"},{\"PermissionName\":\"Edit\",\"Permissions\":\"Administrators\"}]", PageTemplateModules = new List<PageTemplateModule> {
new PageTemplateModule { ModuleDefinitionName = "Oqtane.Modules.Admin.Upgrade, Oqtane.Client", Title = "Upgrade Service", Pane = "Content", ModulePermissions = "[{\"PermissionName\":\"View\",\"Permissions\":\"Administrators\"},{\"PermissionName\":\"Edit\",\"Permissions\":\"Administrators\"}]", Content = "" }
}});
SiteTemplate.Add(new PageTemplate { Name = "RecycleBin", Parent = "Admin", Path = "admin/recyclebin", Icon = "trash", IsNavigation = false, EditMode = true, PagePermissions = "[{\"PermissionName\":\"View\",\"Permissions\":\"Administrators\"},{\"PermissionName\":\"Edit\",\"Permissions\":\"Administrators\"}]", PageTemplateModules = new List<PageTemplateModule> {
new PageTemplateModule { ModuleDefinitionName = "Oqtane.Modules.Admin.RecycleBin, Oqtane.Client", Title = "RecycleBin", Pane = "Content", ModulePermissions = "[{\"PermissionName\":\"View\",\"Permissions\":\"Administrators\"},{\"PermissionName\":\"Edit\",\"Permissions\":\"Administrators\"}]", Content = "" }
SiteTemplate.Add(new PageTemplate { Name = "Recycle Bin", Parent = "Admin", Path = "admin/recyclebin", Icon = "trash", IsNavigation = false, EditMode = true, PagePermissions = "[{\"PermissionName\":\"View\",\"Permissions\":\"Administrators\"},{\"PermissionName\":\"Edit\",\"Permissions\":\"Administrators\"}]", PageTemplateModules = new List<PageTemplateModule> {
new PageTemplateModule { ModuleDefinitionName = "Oqtane.Modules.Admin.RecycleBin, Oqtane.Client", Title = "Recycle Bin", Pane = "Content", ModulePermissions = "[{\"PermissionName\":\"View\",\"Permissions\":\"Administrators\"},{\"PermissionName\":\"Edit\",\"Permissions\":\"Administrators\"}]", Content = "" }
}});
SiteTemplate.Add(new PageTemplate { Name = "Login", Parent = "", Path = "login", Icon = "lock-locked", IsNavigation = false, EditMode = false, PagePermissions = "[{\"PermissionName\":\"View\",\"Permissions\":\"All Users;Administrators\"},{\"PermissionName\":\"Edit\",\"Permissions\":\"Administrators\"}]", PageTemplateModules = new List<PageTemplateModule> {
new PageTemplateModule { ModuleDefinitionName = "Oqtane.Modules.Admin.Login, Oqtane.Client", Title = "User Login", Pane = "Content", ModulePermissions = "[{\"PermissionName\":\"View\",\"Permissions\":\"All Users;Administrators\"},{\"PermissionName\":\"Edit\",\"Permissions\":\"Administrators\"}]", Content = "" }

View File

@ -204,6 +204,30 @@ CREATE TABLE [dbo].[Profile](
GO
CREATE TABLE [dbo].[Log] (
[LogId] [int] IDENTITY(1,1) NOT NULL,
[SiteId] [int] NOT NULL,
[LogDate] [datetime] NOT NULL,
[PageId] [int] NULL,
[ModuleId] [int] NULL,
[UserId] [int] NULL,
[Url] [nvarchar](200) NOT NULL,
[Server] [nvarchar](200) NOT NULL,
[Category] [nvarchar](200) NOT NULL,
[Level] [nvarchar](20) NOT NULL,
[Message] [nvarchar](max) NOT NULL,
[MessageTemplate] [nvarchar](max) NOT NULL,
[Exception] [nvarchar](max) NULL,
[Properties] [nvarchar](max) NULL
CONSTRAINT [PK_Log] PRIMARY KEY CLUSTERED
(
[LogId] ASC
)
)
GO
CREATE TABLE [dbo].[HtmlText](
[HtmlTextId] [int] IDENTITY(1,1) NOT NULL,
[ModuleId] [int] NOT NULL,
@ -275,6 +299,11 @@ REFERENCES [dbo].[Site] ([SiteId])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[Log] WITH CHECK ADD CONSTRAINT [FK_Log_Site] FOREIGN KEY([SiteId])
REFERENCES [dbo].[Site] ([SiteId])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[HtmlText] WITH CHECK ADD CONSTRAINT [FK_HtmlText_Module] FOREIGN KEY([ModuleId])
REFERENCES [dbo].[Module] ([ModuleId])
ON DELETE CASCADE

View File

@ -99,6 +99,7 @@ namespace Oqtane.Server
services.AddScoped<ISettingService, SettingService>();
services.AddScoped<IFileService, FileService>();
services.AddScoped<IPackageService, PackageService>();
services.AddScoped<ILogService, LogService>();
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
@ -173,6 +174,8 @@ namespace Oqtane.Server
services.AddTransient<IUserRoleRepository, UserRoleRepository>();
services.AddTransient<IPermissionRepository, PermissionRepository>();
services.AddTransient<ISettingRepository, SettingRepository>();
services.AddTransient<ILogRepository, LogRepository>();
services.AddTransient<ILogManager, LogManager>();
// get list of loaded assemblies
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
@ -360,6 +363,8 @@ namespace Oqtane.Server
services.AddTransient<IUserRoleRepository, UserRoleRepository>();
services.AddTransient<IPermissionRepository, PermissionRepository>();
services.AddTransient<ISettingRepository, SettingRepository>();
services.AddTransient<ILogRepository, LogRepository>();
services.AddTransient<ILogManager, LogManager>();
// get list of loaded assemblies
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 MiB