Where & How Castle Windsor sets up logging facility

前端 未结 3 1102
慢半拍i
慢半拍i 2020-12-28 10:12

I\'m fairly new to Castle Windsor and am looking into the in\'s and out\'s of the logging facility. It seems fairly impressive but the only thing i can\'t work out is where

3条回答
  •  -上瘾入骨i
    2020-12-28 10:35

    You can also configure this programatically when you initialise windsor (e.g. from your global.asax.cs):

    container.AddFacility("logging",  new LoggingFacility(LoggerImplementation.Log4net));
    

    You can of course choose any of the logger implimentations.

    This this will be wired up whenever windsor instantiates any class expecting a logger. I wouldn't put this in the constructor as it's a cross cutting concern - better to do like you suggested in my opinion. You can simplify it a little:

        private ILogger logger = NullLogger.Instance;
        public ILogger Logger
        {
            get { return logger; }
            set { logger = value; }
        }
    

提交回复
热议问题