c# - log4net:使用 ILog 与 ILogger 之间的区别/优势是什么?

标签 c# logging log4net

在下面的代码示例中,使用了这两种方法。还有一个类似的问题here ,但没有给出真正的解释,我也无法对帖子发表评论。

public static partial class Log
{
    private readonly static Type ThisDeclaringType = typeof(Log);
    private static readonly ILogger defaultLogger;
    private static readonly ILog defaultLog;

    // Setup our default logger
    static Log()
    {
        defaultLogger = LoggerManager.GetLogger(Assembly.GetCallingAssembly(), "CTWorkManager");
        defaultLog = LogManager.GetLogger(Assembly.GetCallingAssembly(), "CTWorkManager");
    }

    public static void Info(object message)
    {
        if (defaultLogger.IsEnabledFor(Level.Info))
        {
            defaultLogger.Log(ThisDeclaringType, Level.Info, message, null);
        }
        if (defaultLog.IsInfoEnabled)
        {
            defaultLog.Info(message, null);
        }
    }
    // etc...
}

最佳答案

ILogger 是所有记录器实现的接口(interface)。该接口(interface)定义了对开发有用的其他方法,例如IsEnabledFor(级别级别)。您可以使用 ILogger 来实现您自己的自定义记录器。您应该在应用程序中使用 ILog 接口(interface)来记录消息。

关于c# - log4net:使用 ILog 与 ILogger 之间的区别/优势是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52751031/

相关文章:

wcf - 记录 WCF 服务收到的请求

java - 如何从 Java 写入 Windows 事件日志?

azure - Azure 上的 Log4Net

nuget - 无法加载类型 'Common.Logging.Factory.AbstractCachingLoggerFactoryAdapter'

c# - 使用 asp-ajax 按顺序加载项目并提高 Web 应用程序速度

c# - 如何自动生成免费接收和存储服务的构造函数?

backup - rsync 日志中的 f++++++++++ 是什么意思?

c# - 用于短期内存的 ASP.NET 自定义控件

c# - 什么时候使用哪个?

c# - log4net 将在哪里创建这个日志文件?