為了不用重覆define variables, 在 OO 中通常會將common property / method 放到abstract class 中, 再讓其他child class 繼承. 而在log4net 中, 要設定其logger, 若用回之前的設定, 便會指向其parent class.
若要解決的話, 其實只須叫用logger 時改用GetType()便可. 例如:
public abstract class BaseController { private ILog _log; /// <summary> /// Logger defined in base class for troubleshooting. /// </summary> protected ILog _logger { get { if (_log == null) { _log = LogManager.GetLogger(this.GetType()); } return _log; } } }
Leave a Reply