示例#1
0
        public static ILogger <TDataItem> Validate <TDataItem>(this ILogger <TDataItem> logger, IKernel kernel)
        {
            ILoggerInternal loggerInternal = logger as ILoggerInternal;

            if (loggerInternal == null)
            {
                throw new ArgumentException("logger must implement ILoggerInternal");
            }

            ConfigurationValidationResult result = new ConfigurationValidationResult();

            if (!InterceptionEnabled(kernel))
            {
                result.AddError("Castle binding not set. Call BindToWindsor method.");
            }

            ConfigurationValidationResult innerValidationResult = ((ILoggerInternal)logger).ValidateConfiguration(
                new DeclaringTypeMustBeAccessibleForProxyCreating(),
                new DeclaringTypeCannotBeOpenGeneric(),
                new DeclaringTypeCannotBeInterface(),
                new ReturnsSatisfiedIfUnableToCheck(
                    new MethodMustBeVirtualIfDeclaringTypeRegisteredOnlyForItself(kernel)),
                new DeclaringTypeMustBeRegisteredInContainer(kernel),
                new ReturnsSatisfiedIfUnableToCheck(
                    new DeclaringNonGenericTypeMustBeRegisteredInContainerAfterLoggerConfigured(kernel)));

            result.CopyErrorsFrom(innerValidationResult);

            if (!result.IsValid)
            {
                throw new LoggerValidationException(result);
            }

            return(logger);
        }
示例#2
0
        public static ILogger <TDataItem> BindToWindsor <TDataItem>(this ILogger <TDataItem> logger, IKernel kernel)
        {
            ILoggerInternal loggerInternal = logger as ILoggerInternal;

            if (loggerInternal == null)
            {
                throw new ArgumentException("logger must implement ILoggerInternal");
            }

            if (!InterceptionEnabled(kernel))
            {
                EnableInterception(kernel);
            }

            ICompositeLoggerInternal compositeLoggerInternal = kernel.Resolve <ICompositeLoggerInternal>();

            if (compositeLoggerInternal.Has((ILoggerInternal)logger))
            {
                throw new InvalidOperationException("Logger already bound");
            }

            compositeLoggerInternal.Add((ILoggerInternal)logger);

            return(logger.SetContainer(new WindsorContainerWrapper(kernel)));
        }
示例#3
0
        public void Add(ILoggerInternal loggerInternal)
        {
            if (Has(loggerInternal))
            {
                throw new Exception("Logger already added");
            }

            _loggers.Add(loggerInternal);
        }
示例#4
0
 public bool Has(ILoggerInternal loggerInternal)
 {
     return(_loggers.Contains(loggerInternal));
 }