Exemplo n.º 1
0
        // cannot be instantiated
        public static IConnectionProvider NewConnectionProvider(IDictionary <string, string> settings)
        {
            IConnectionProvider connections;
            string providerClass;

            if (settings.TryGetValue(Environment.ConnectionProvider, out providerClass))
            {
                try
                {
                    log.Info("Initializing connection provider: " + providerClass);
                    connections =
                        (IConnectionProvider)
                        Environment.BytecodeProvider.ObjectsFactory.CreateInstance(ReflectHelper.ClassForName(providerClass));
                }
                catch (Exception e)
                {
                    log.Fatal("Could not instantiate connection provider", e);
                    throw new HibernateException("Could not instantiate connection provider: " + providerClass, e);
                }
            }
            else if (settings.ContainsKey(Environment.ConnectionString) || settings.ContainsKey(Environment.ConnectionStringName))
            {
                connections = new DriverConnectionProvider();
            }
            else
            {
                log.Info("No connection provider specified, UserSuppliedConnectionProvider will be used.");
                connections = new UserSuppliedConnectionProvider();
            }
            connections.Configure(settings);
            return(connections);
        }
Exemplo n.º 2
0
        public void FatalTest()
        {
            IInternalLogger target = CreateLogger();

            target.SetLevel(LogLevel.Always);
            calls = 0;
            target.Fatal(message, ex);
            Assert.AreEqual(calls, 0);
            calls = 0;
            target.SetLevel(LogLevel.All);
            target.Fatal(message, ex);
            Assert.AreEqual(calls, 1);
            calls = 0;
            target.SetLevel(LogLevel.Fatal);
            target.Fatal(message, ex);
            Assert.AreEqual(calls, 1);
            Assert.AreEqual(lastItem.Category, category);
            Assert.AreEqual(lastItem.Level, LogLevel.Fatal);
            Assert.IsNotNull(lastItem.Ex);
            Assert.AreEqual(lastItem.Ex, ex);
            Assert.AreEqual(lastItem.Message, message);
            Assert.IsNotNull(lastItem.Ids);
        }
        public static ILinqToHqlGeneratorsRegistry CreateGeneratorsRegistry(IDictionary <string, string> properties)
        {
            string registry;

            if (properties.TryGetValue(Environment.LinqToHqlGeneratorsRegistry, out registry))
            {
                try
                {
                    log.Info("Initializing LinqToHqlGeneratorsRegistry: " + registry);
                    return((ILinqToHqlGeneratorsRegistry)Environment.BytecodeProvider.ObjectsFactory.CreateInstance(ReflectHelper.ClassForName(registry)));
                }
                catch (Exception e)
                {
                    log.Fatal("Could not instantiate LinqToHqlGeneratorsRegistry", e);
                    throw new HibernateException("Could not instantiate LinqToHqlGeneratorsRegistry: " + registry, e);
                }
            }
            return(new DefaultLinqToHqlGeneratorsRegistry());
        }
Exemplo n.º 4
0
        public void Log(NHibernateLogLevel logLevel, NHibernateLogValues state, Exception exception)
        {
            if (!IsEnabled(logLevel))
            {
                return;
            }

            switch (logLevel)
            {
            case NHibernateLogLevel.Debug:
            case NHibernateLogLevel.Trace:
                if (exception != null)
                {
                    _internalLogger.Debug(state, exception);
                }
                else if (state.Args?.Length > 0)
                {
                    _internalLogger.DebugFormat(state.Format, state.Args);
                }
                else
                {
                    _internalLogger.Debug(state);
                }
                break;

            case NHibernateLogLevel.Info:
                if (exception != null)
                {
                    _internalLogger.Info(state, exception);
                }
                else if (state.Args?.Length > 0)
                {
                    _internalLogger.InfoFormat(state.Format, state.Args);
                }
                else
                {
                    _internalLogger.Info(state);
                }
                break;

            case NHibernateLogLevel.Warn:
                if (exception != null)
                {
                    _internalLogger.Warn(state, exception);
                }
                else if (state.Args?.Length > 0)
                {
                    _internalLogger.WarnFormat(state.Format, state.Args);
                }
                else
                {
                    _internalLogger.Warn(state);
                }
                break;

            case NHibernateLogLevel.Error:
                if (exception != null)
                {
                    _internalLogger.Error(state, exception);
                }
                else if (state.Args?.Length > 0)
                {
                    _internalLogger.ErrorFormat(state.Format, state.Args);
                }
                else
                {
                    _internalLogger.Error(state);
                }
                break;

            case NHibernateLogLevel.Fatal:
                if (exception != null)
                {
                    _internalLogger.Fatal(state, exception);
                }
                else
                {
                    _internalLogger.Fatal(state);
                }
                break;

            case NHibernateLogLevel.None:
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(logLevel), logLevel, null);
            }
        }
Exemplo n.º 5
0
        public void Fatal(string message, params object[] args)
        {
            var messageToTrace = string.Format(CultureInfo.InvariantCulture, message, args);

            logger.Fatal(messageToTrace);
        }