在下面的代码示例中,使用了这两种方法。还有一个类似的问题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/