Beispiel #1
0
        private static void EmitFactoryResolverError(IFactoryResolver resolver)
        {
            var msg = "The factory resolver " + resolver.GetType().Name
                      + " returned null from GetFactory().  The fallback no operation logger factory will be used instead.";

            EventLogHelper.WriteEntry(msg, null);
        }
Beispiel #2
0
        private static void PerformInitialization()
        {
            try
            {
                if (_factoryResolver == null)
                {
                    _factoryResolver = new AppConfigFactoryResolver();
                }

                var factory = _factoryResolver.GetFactory();

                if (factory == null)
                {
                    _initializationState = InitializationState.NOP_Fallback;
                    EmitFactoryResolverError(_factoryResolver);
                    return;
                }

                _initializationState = InitializationState.Initialized;
                EmitSubstituteLoggerWarning();
            }
            catch (Exception ex)
            {
                _initializationState = InitializationState.NOP_Fallback;

                try
                {
                    EventLogHelper.WriteEntry("Error initializing LoggerFactory.  Defaulting to no-operation (NOP) logger implementation.", ex);
                }
                catch { }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Discards customizations and resets the configured logger
        /// facilities to their defaults. For Silverlight, this means
        /// that the service returns <see cref="NullLogger"/> instances
        /// for all requests. In other environments, the class falls
        /// back to loggers that were configured through <c>app.config</c>.
        /// </summary>
        public static void Reset()
        {
#if SILVERLIGHT
            factoryResolver = NullLoggerFactoryResolver.Instance;
#else
            factoryResolver = new AppConfigFactoryResolver();
#endif
        }
Beispiel #4
0
 /// <summary>
 /// Sets the factory resolver used to get the <see cref="ILoggerFactory"/>
 /// </summary>
 /// <param name="resolver">The resolver to use.  If null is passed, the <see cref="NOPLoggerFactoryResolver"/> will be used.</param>
 public static void SetFactoryResolver(IFactoryResolver resolver)
 {
     lock (_locker)
     {
         _initializationState = InitializationState.Uninitialized;
         _factoryResolver     = resolver ?? NOPLoggerFactoryResolver.Instance;
     }
 }
Beispiel #5
0
 /// <summary>
 /// Discards customizations and resets the configured logger
 /// facilities to their defaults.
 /// </summary>
 public static void Reset()
 {
     lock (_locker)
     {
         _initializationState = InitializationState.Uninitialized;
         _tempFactory         = new SubstituteLoggerFactory();
         _factoryResolver     = null;
     }
 }
Beispiel #6
0
        public void FactoryResolverTest()
        {
            IFactoryResolver expected = null; // TODO: Initialize to an appropriate value
            IFactoryResolver actual;

            LogManager.FactoryResolver = expected;
            actual = LogManager.FactoryResolver;
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
        public void LoggerFactory_SetFactoryResolverTest()
        {
            IFactoryResolver resolver = MoqFactory.FactoryResolver().Object;

            LoggerFactory.SetFactoryResolver(resolver);

            var factory = LoggerFactory.GetILoggerFactory();

            Assert.IsInstanceOfType(factory, resolver.GetFactory().GetType());
        }
Beispiel #8
0
        private static void PerformInitialization()
        {
            try
            {
                if (_factoryResolver == null)
                {
                    _factoryResolver = new AppConfigFactoryResolver();
                }

                var factory = _factoryResolver.GetFactory();

                if (factory == null)
                {
                    _initializationState = InitializationState.NOP_Fallback;
                    EmitFactoryResolverError(_factoryResolver);
                    return;
                }

                _initializationState = InitializationState.Initialized;
                EmitSubstituteLoggerWarning();

            }
            catch (Exception ex)
            {
                _initializationState = InitializationState.NOP_Fallback;

                try
                {
                    EventLogHelper.WriteEntry("Error initializing LoggerFactory.  Defaulting to no-operation (NOP) logger implementation.", ex);
                }
                catch { }
            }
        }
Beispiel #9
0
        private static void EmitFactoryResolverError(IFactoryResolver resolver)
        {
            var msg = "The factory resolver " + resolver.GetType().Name
                + " returned null from GetFactory().  The fallback no operation logger factory will be used instead.";

            EventLogHelper.WriteEntry(msg, null);
        }
Beispiel #10
0
 /// <summary>
 /// Sets the factory resolver used to get the <see cref="ILoggerFactory"/>
 /// </summary>
 /// <param name="resolver">The resolver to use.  If null is passed, the <see cref="NOPLoggerFactoryResolver"/> will be used.</param>
 public static void SetFactoryResolver(IFactoryResolver resolver)
 {
     lock (_locker)
     {
         _initializationState = InitializationState.Uninitialized;
         _factoryResolver = resolver ?? NOPLoggerFactoryResolver.Instance;
     }
 }
Beispiel #11
0
 /// <summary>
 /// Discards customizations and resets the configured logger
 /// facilities to their defaults.
 /// </summary>
 public static void Reset()
 {
     lock (_locker)
     {
         _initializationState = InitializationState.Uninitialized;
         _tempFactory = new SubstituteLoggerFactory();
         _factoryResolver = null;
     }
 }
Beispiel #12
0
        /// <summary>
        /// Plugs in a single <see cref="ILogger"/> instance that will be returned
        /// for all requests, including requests for named loggers
        /// (both <see cref="GetLogger()"/> and <see cref="GetLogger(string)"/>
        /// methods).
        /// </summary>
        /// <param name="loggerImplementation">The logger to be
        /// used globally. A null reference is a valid parameter value which resets
        /// the service to return a <see cref="NullLogger"/> instance.</param>
        /// <remarks>Assigning a logger through this method creates a custom
        /// <see cref="IFactoryResolver"/>. This resolver replaces the current
        /// <see cref="FactoryResolver"/> property in order to always return
        /// the submitted <paramref name="loggerImplementation"/> if
        /// <see cref="GetLogger()"/> or <see cref="GetLogger(string)"/> is being
        /// invoked.</remarks>
        public static void SetLogger(ILogger loggerImplementation)
        {
            ILogger logger = loggerImplementation ?? NullLogger.Instance;

            FactoryResolver = new SimpleLoggerResolver(logger);
        }
Beispiel #13
0
        /// <summary> Plugs in a single <see cref="ILog" /> instance that will be returned for all requests, including requests for named logs (both <see cref="GetLog()" /> and <see cref="GetLog(string)" />
        ///     methods). </summary>
        /// <param name="logImplementation"> The log to be used globally. A null reference is a valid parameter value which resets the service to return a <see cref="NullLog" /> instance. </param>
        /// <remarks> Assigning a log through this method creates a custom <see cref="IFactoryResolver" />. This resolver replaces the current <see cref="FactoryResolver" /> property in order to always return
        ///     the submitted <paramref name="logImplementation" /> if <see cref="GetLog()" /> or <see cref="GetLog(string)" /> is being invoked. </remarks>
        public static void SetLog(ILog logImplementation)
        {
            ILog log = logImplementation ?? NullLog.Instance;

            FactoryResolver = new SimpleLogResolver(log);
        }