Merge pull request #2997 from sbwalker/dev
fix #2976 - add logging methods to ThemeBase
This commit is contained in:
commit
e823e371f6
|
@ -9,7 +9,6 @@ using Oqtane.UI;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.JSInterop;
|
using Microsoft.JSInterop;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Oqtane.Themes;
|
|
||||||
|
|
||||||
namespace Oqtane.Modules
|
namespace Oqtane.Modules
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,7 +19,6 @@ namespace Oqtane.Themes.Controls
|
||||||
[Inject] public IUserService UserService { get; set; }
|
[Inject] public IUserService UserService { get; set; }
|
||||||
[Inject] public IJSRuntime jsRuntime { get; set; }
|
[Inject] public IJSRuntime jsRuntime { get; set; }
|
||||||
[Inject] public IServiceProvider ServiceProvider { get; set; }
|
[Inject] public IServiceProvider ServiceProvider { get; set; }
|
||||||
[Inject] public ILogService LoggingService { get; set; }
|
|
||||||
|
|
||||||
protected void LoginUser()
|
protected void LoginUser()
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
using Microsoft.JSInterop;
|
using Microsoft.JSInterop;
|
||||||
|
using Oqtane.Enums;
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
|
using Oqtane.Modules;
|
||||||
|
using Oqtane.Services;
|
||||||
using Oqtane.Shared;
|
using Oqtane.Shared;
|
||||||
using Oqtane.UI;
|
using Oqtane.UI;
|
||||||
using System;
|
using System;
|
||||||
|
@ -13,6 +16,9 @@ namespace Oqtane.Themes
|
||||||
{
|
{
|
||||||
public abstract class ThemeBase : ComponentBase, IThemeControl
|
public abstract class ThemeBase : ComponentBase, IThemeControl
|
||||||
{
|
{
|
||||||
|
[Inject]
|
||||||
|
protected ILogService LoggingService { get; set; }
|
||||||
|
|
||||||
[Inject]
|
[Inject]
|
||||||
protected IJSRuntime JSRuntime { get; set; }
|
protected IJSRuntime JSRuntime { get; set; }
|
||||||
|
|
||||||
|
@ -186,6 +192,148 @@ namespace Oqtane.Themes
|
||||||
await interop.ScrollTo(0, 0, "smooth");
|
await interop.ScrollTo(0, 0, "smooth");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// logging methods
|
||||||
|
public async Task Log(Alias alias, LogLevel level, string function, Exception exception, string message, params object[] args)
|
||||||
|
{
|
||||||
|
LogFunction logFunction;
|
||||||
|
if (string.IsNullOrEmpty(function))
|
||||||
|
{
|
||||||
|
// try to infer from page action
|
||||||
|
function = PageState.Action;
|
||||||
|
}
|
||||||
|
if (!Enum.TryParse(function, out logFunction))
|
||||||
|
{
|
||||||
|
switch (function.ToLower())
|
||||||
|
{
|
||||||
|
case "add":
|
||||||
|
logFunction = LogFunction.Create;
|
||||||
|
break;
|
||||||
|
case "edit":
|
||||||
|
logFunction = LogFunction.Update;
|
||||||
|
break;
|
||||||
|
case "delete":
|
||||||
|
logFunction = LogFunction.Delete;
|
||||||
|
break;
|
||||||
|
case "":
|
||||||
|
logFunction = LogFunction.Read;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
logFunction = LogFunction.Other;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await Log(alias, level, logFunction, exception, message, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task Log(Alias alias, LogLevel level, LogFunction function, Exception exception, string message, params object[] args)
|
||||||
|
{
|
||||||
|
int pageId = PageState.Page.PageId;
|
||||||
|
string category = GetType().AssemblyQualifiedName;
|
||||||
|
string feature = Utilities.GetTypeNameLastSegment(category, 1);
|
||||||
|
|
||||||
|
await LoggingService.Log(alias, pageId, null, PageState.User?.UserId, category, feature, function, level, exception, message, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Logger
|
||||||
|
{
|
||||||
|
private readonly ModuleBase _moduleBase;
|
||||||
|
|
||||||
|
public Logger(ModuleBase moduleBase)
|
||||||
|
{
|
||||||
|
_moduleBase = moduleBase;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task LogTrace(string message, params object[] args)
|
||||||
|
{
|
||||||
|
await _moduleBase.Log(null, LogLevel.Trace, "", null, message, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task LogTrace(LogFunction function, string message, params object[] args)
|
||||||
|
{
|
||||||
|
await _moduleBase.Log(null, LogLevel.Trace, function, null, message, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task LogTrace(Exception exception, string message, params object[] args)
|
||||||
|
{
|
||||||
|
await _moduleBase.Log(null, LogLevel.Trace, "", exception, message, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task LogDebug(string message, params object[] args)
|
||||||
|
{
|
||||||
|
await _moduleBase.Log(null, LogLevel.Debug, "", null, message, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task LogDebug(LogFunction function, string message, params object[] args)
|
||||||
|
{
|
||||||
|
await _moduleBase.Log(null, LogLevel.Debug, function, null, message, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task LogDebug(Exception exception, string message, params object[] args)
|
||||||
|
{
|
||||||
|
await _moduleBase.Log(null, LogLevel.Debug, "", exception, message, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task LogInformation(string message, params object[] args)
|
||||||
|
{
|
||||||
|
await _moduleBase.Log(null, LogLevel.Information, "", null, message, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task LogInformation(LogFunction function, string message, params object[] args)
|
||||||
|
{
|
||||||
|
await _moduleBase.Log(null, LogLevel.Information, function, null, message, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task LogInformation(Exception exception, string message, params object[] args)
|
||||||
|
{
|
||||||
|
await _moduleBase.Log(null, LogLevel.Information, "", exception, message, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task LogWarning(string message, params object[] args)
|
||||||
|
{
|
||||||
|
await _moduleBase.Log(null, LogLevel.Warning, "", null, message, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task LogWarning(LogFunction function, string message, params object[] args)
|
||||||
|
{
|
||||||
|
await _moduleBase.Log(null, LogLevel.Warning, function, null, message, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task LogWarning(Exception exception, string message, params object[] args)
|
||||||
|
{
|
||||||
|
await _moduleBase.Log(null, LogLevel.Warning, "", exception, message, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task LogError(string message, params object[] args)
|
||||||
|
{
|
||||||
|
await _moduleBase.Log(null, LogLevel.Error, "", null, message, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task LogError(LogFunction function, string message, params object[] args)
|
||||||
|
{
|
||||||
|
await _moduleBase.Log(null, LogLevel.Error, function, null, message, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task LogError(Exception exception, string message, params object[] args)
|
||||||
|
{
|
||||||
|
await _moduleBase.Log(null, LogLevel.Error, "", exception, message, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task LogCritical(string message, params object[] args)
|
||||||
|
{
|
||||||
|
await _moduleBase.Log(null, LogLevel.Critical, "", null, message, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task LogCritical(LogFunction function, string message, params object[] args)
|
||||||
|
{
|
||||||
|
await _moduleBase.Log(null, LogLevel.Critical, function, null, message, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task LogCritical(Exception exception, string message, params object[] args)
|
||||||
|
{
|
||||||
|
await _moduleBase.Log(null, LogLevel.Critical, "", exception, message, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Obsolete("ContentUrl(int fileId) is deprecated. Use FileUrl(int fileId) instead.", false)]
|
[Obsolete("ContentUrl(int fileId) is deprecated. Use FileUrl(int fileId) instead.", false)]
|
||||||
public string ContentUrl(int fileid)
|
public string ContentUrl(int fileid)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user