namespace NModbus.Logging
{
///
/// Base class for Modbus loggers.
///
public abstract class ModbusLogger : IModbusLogger
{
protected ModbusLogger(LoggingLevel minimumLoggingLevel)
{
MinimumLoggingLevel = minimumLoggingLevel;
}
protected LoggingLevel MinimumLoggingLevel { get; }
///
/// Returns true if the level should be loggged, false otherwise.
///
///
///
public bool ShouldLog(LoggingLevel level)
{
return level >= MinimumLoggingLevel;
}
///
/// Log the specified message at the specified level.
///
///
///
public void Log(LoggingLevel level, string message)
{
if (ShouldLog(level))
{
LogCore(level, message);
}
}
///
/// Override this method to implement logging behavior. This function will only be called if ShouldLog(level) is true.
///
///
///
protected abstract void LogCore(LoggingLevel level, string message);
}
}