2026-10-03 15:26:21 +02:00
|
|
|
namespace decePubClient.Services;
|
|
|
|
|
|
|
|
|
|
public interface ILoggingService
|
|
|
|
|
{
|
|
|
|
|
ValueTask ProcessError(Exception exception, string where, CancellationToken cancellationToken = default);
|
|
|
|
|
|
|
|
|
|
ValueTask ProcessError(string message, string where, CancellationToken cancellationToken = default);
|
|
|
|
|
|
|
|
|
|
ValueTask ProcessWarning(string message, string where, CancellationToken cancellationToken = default);
|
|
|
|
|
|
|
|
|
|
void Process(string message, string where = default, LogLevel level = LogLevel.Information);
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-17 02:56:57 +02:00
|
|
|
/// <summary>Writes to the browser console through ILogger.</summary>
|
|
|
|
|
public class LoggingService(ILogger<LoggingService> logger) : ILoggingService
|
2026-10-03 15:26:21 +02:00
|
|
|
{
|
|
|
|
|
public void Process(string message, string where = default, LogLevel level = LogLevel.Information) =>
|
|
|
|
|
logger.Log(level, "[{Where}] {Message}", where ?? "N/A", message);
|
|
|
|
|
|
2026-10-17 02:56:57 +02:00
|
|
|
public ValueTask ProcessError(Exception exception, string where, CancellationToken cancellationToken = default)
|
2026-10-03 15:26:21 +02:00
|
|
|
{
|
2026-10-17 02:56:57 +02:00
|
|
|
logger.LogError(exception, "[{Where}]", where);
|
|
|
|
|
return ValueTask.CompletedTask;
|
2026-10-03 15:26:21 +02:00
|
|
|
}
|
|
|
|
|
|
2026-10-17 02:56:57 +02:00
|
|
|
public ValueTask ProcessError(string message, string where, CancellationToken cancellationToken = default)
|
2026-10-03 15:26:21 +02:00
|
|
|
{
|
2026-10-17 02:56:57 +02:00
|
|
|
logger.LogError("[{Where}] {Message}", where, message);
|
|
|
|
|
return ValueTask.CompletedTask;
|
2026-10-03 15:26:21 +02:00
|
|
|
}
|
|
|
|
|
|
2026-10-17 02:56:57 +02:00
|
|
|
public ValueTask ProcessWarning(string message, string where, CancellationToken cancellationToken = default)
|
2026-10-03 15:26:21 +02:00
|
|
|
{
|
2026-10-17 02:56:57 +02:00
|
|
|
logger.LogWarning("[{Where}] {Message}", where, message);
|
|
|
|
|
return ValueTask.CompletedTask;
|
2026-10-03 15:26:21 +02:00
|
|
|
}
|
|
|
|
|
}
|