TourIAm/TIAMWebApp/Shared/Utility/BrowserConsoleLogWriter.cs

47 lines
1.4 KiB
C#

using AyCode.Core.Enums;
using AyCode.Core.Loggers;
using AyCode.Services.Loggers;
using Microsoft.JSInterop;
namespace TIAMWebApp.Shared.Application.Utility;
//public interface IBrowserConsoleLogWriter : IAcLogWriterBase
//{ }
//public abstract class LogWriterClient : AcTextLogWriterBase
//{
// protected LogWriterClient(IJSRuntime jsRuntime) : base(AppType.Web, LogLevel.Debug)
// { }
//}
public class BrowserConsoleLogWriter : AcTextLogWriterBase, IAcLogWriterClientBase
{
private readonly IJSRuntime _jsRuntime;
private readonly Dictionary<LogLevel, string> _invokeConsoleNames = new()
{
[LogLevel.Detail] = "console.info", //trace
[LogLevel.Trace] = "console.info",
[LogLevel.Debug] = "console.info",
[LogLevel.Info] = "console.info",
[LogLevel.Suggest] = "console.info",
[LogLevel.Warning] = "console.warn",
[LogLevel.Error] = "console.error"
};
public BrowserConsoleLogWriter(IJSRuntime jsRuntime) : base(AppType.Web, LogLevel.Info)
{
_jsRuntime = jsRuntime;
}
protected override void WriteText(string? logText, LogLevel logLevel)
{
_jsRuntime.InvokeVoidAsync(_invokeConsoleNames[logLevel], logText); //logText?.Replace(Environment.NewLine, "<br />"));
}
//public void Info(string message)
//{
// ((AcLogWriterBase)this).Info(message);
// //jsRuntime.InvokeVoidAsync("console.log", logText);
//}
}