Skip to content

Please remove the Microsoft.Extensions.Logging.Abstractions dependency from the next version. #2589

@pairbit

Description

@pairbit

Right now I made a fork without the dependency Microsoft.Extensions.Logging.Abstractions https://github.com/pairbit/IT.Redis

The fact is that Microsoft.Extensions.Logging.LoggerExtensions are very bad, they are prohibited from being used in our projects.

Please create your own IRedisLogger interface without params object[]. Also replace the ILoggerFactory type with the Func<Type,IRedisLogger> delegate.

namespace StackExchange.Redis;

public interface IRedisLogger
{
    void Log(int level, Exception? exception, string? message);
}

and

namespace StackExchange.Redis.Configuration;

public class DefaultOptionsProvider
{
    public virtual Func<Type, IRedisLogger>? LoggerFactory => null;
}

and internal extension for logging

internal enum Level
{
    Trace,
    Debug,
    Information,
    Warning,
    Error,
    Critical,
    None
}

internal static class IRedisLoggerExtensions
{
    public static void LogInformation(this IRedisLogger logger, string? message)
        => logger.Log((int)Level.Information, null, message);

    public static void LogTrace(this IRedisLogger logger, string? message)
        => logger.Log((int)Level.Trace, null, message);

    public static void LogInformation(this IRedisLogger logger, Exception? exception, string? message)
        => logger.Log((int)Level.Information, exception, message);

    public static void LogError(this IRedisLogger logger, Exception? exception, string? message)
        => logger.Log((int)Level.Error, exception, message);
}

internal static class LoggerFactoryExtensions
{
    public static ILogger CreateLogger<T>(this Func<Type, IRedisLogger> factory)
        => factory(typeof(T));
}

I see that you do not use logging with params object[], but I primarily liked your library for its small number of dependencies.

Please do not close the ticket immediately. Consider my proposal. Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions