Exemplo n.º 1
0
        public ILogger CreateLogger(LoggerConfigurationOptions options)
        {
            var log        = LogManager.GetLogger(options.Name);
            var properties = new Dictionary <string, object> {
                { "category", options.Category }
            };

            return(new Log4NetLogger(log, properties));
        }
        private void InjectLogger(PropertyDescriptor loggerProperty, IBuilderContext context)
        {
            var loggerConfigurationOptions = new LoggerConfigurationOptions();
            var loggerAttribute            = (LoggerAttribute)loggerProperty.Attributes[typeof(LoggerAttribute)];

            loggerConfigurationOptions.Category = loggerAttribute != null ? loggerAttribute.Category : Category.Default;

            if (loggerAttribute != null && !string.IsNullOrEmpty(loggerAttribute.Name))
            {
                loggerConfigurationOptions.Name = loggerAttribute.Name;
            }
            else
            {
                loggerConfigurationOptions.Name = context.BuildKey.Type.Name;
            }

            var loggerFactory  = _container.Resolve <ILoggerFactory>();
            var loggerInstance = loggerFactory.CreateLogger(loggerConfigurationOptions);

            loggerProperty.SetValue(context.Existing, loggerInstance);
        }