Files
decePubClient/Services/ILoggingService.cs
T

37 lines
1.4 KiB
C#
Raw Normal View History

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);
}
/// <summary>Writes to the browser console through ILogger.</summary>
public class LoggingService(ILogger<LoggingService> logger) : ILoggingService
{
public void Process(string message, string where = default, LogLevel level = LogLevel.Information) =>
logger.Log(level, "[{Where}] {Message}", where ?? "N/A", message);
public ValueTask ProcessError(Exception exception, string where, CancellationToken cancellationToken = default)
{
logger.LogError(exception, "[{Where}]", where);
return ValueTask.CompletedTask;
}
public ValueTask ProcessError(string message, string where, CancellationToken cancellationToken = default)
{
logger.LogError("[{Where}] {Message}", where, message);
return ValueTask.CompletedTask;
}
public ValueTask ProcessWarning(string message, string where, CancellationToken cancellationToken = default)
{
logger.LogWarning("[{Where}] {Message}", where, message);
return ValueTask.CompletedTask;
}
}