コード例 #1
0
ファイル: Global.asax.cs プロジェクト: themanowar77/myaplwin
        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            log4net.Config.XmlConfigurator.Configure();
            var filter = new log4net.Filter.LoggerMatchFilter();
            filter.LoggerToMatch = "NHibernate.SQL";
            filter.AcceptOnMatch = true;

            var filterDeny = new log4net.Filter.DenyAllFilter();

            var appender = new log4net.Appender.DebugAppender
            {
                Layout = new log4net.Layout.SimpleLayout(),
                Name = "NHibernate.SQL",
                Threshold = log4net.Core.Level.Debug
            };

            appender.AddFilter(filter);
            appender.AddFilter(filterDeny);
            log4net.Config.BasicConfigurator.Configure(appender);
            //_sessionHelper.OpenSession("FHG");
            _sessionHelper.OpenSession("APL");
        }
コード例 #2
0
ファイル: Logger.cs プロジェクト: mythsya/db-plugins
        private static void SetupLogger()
        {
            try
            {
                if (trinityLog == null)
                {
                    lock (_loglock)
                    {
                        _Logger.Info("Setting up Trinity Logging");
                        int myPid = Process.GetCurrentProcess().Id;
                        DateTime startTime = Process.GetCurrentProcess().StartTime;

                        trinityLayout = new PatternLayout("%date{HH:mm:ss.fff} %-5level %logger{1} %m%n");
                        trinityLayout.ActivateOptions();

                        trinityFilter = new log4net.Filter.LoggerMatchFilter();
                        trinityFilter.LoggerToMatch = "Trinity";
                        trinityFilter.AcceptOnMatch = true;
                        trinityFilter.ActivateOptions();

                        Hierarchy h = (Hierarchy)LogManager.GetRepository();
                        var appenders = h.GetAppenders();

                        foreach (var appender in appenders)
                        {
                            if (appender is FileAppender)
                            {
                                trinityAppender = appender as FileAppender;
                            }
                        }

                        trinityAppender.Layout = trinityLayout;
                        //trinityAppender.AddFilter(trinityFilter);
                        trinityAppender.LockingModel = new FileAppender.ExclusiveLock();
                        //trinityAppender.LockingModel = new FileAppender.InterProcessLock();

                        trinityAppender.ActivateOptions();

                        trinityLog = LogManager.GetLogger("TrinityDebug");
                        trinityLogger = ((log4net.Repository.Hierarchy.Logger)trinityLog.Logger);
                        trinityLogger.Additivity = false;
                        trinityLogger.AddAppender(trinityAppender);
                    }
                }
            }
            catch (Exception ex)
            {
                _Logger.Error("Error setting up Trinity Logger:\n" + ex.ToString());
            }
        }
コード例 #3
0
        /// <summary>
        /// Return a session from the SessionLibrary
        /// </summary>
        /// <param name="dbId"></param>
        /// <returns></returns>
        public static ISessionFactory GetSessionFactory(string dbId)
        {
            lock (factorylock)
            {
                if (!SessionFactoryLib.ContainsKey(dbId) || SessionFactoryLib[dbId] == null)
                {
                    if (HttpRuntime.AppDomainAppId == null)
                    {
                        _sessionContext = "thread_static";
                        _dbConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).GetSection("databases") as MyConfig.DatabaseRetrieverSection;
                    } else
                    {
                        _dbConfig = ConfigurationManager.GetSection("databases") as MyConfig.DatabaseRetrieverSection;
                    }
                    Type t = Type.GetType(GetDBMappingClass(dbId));
                    var configuration = Fluently.Configure().
                        Database(MsSqlConfiguration.MsSql2008.ConnectionString(GetDBConnectionString(dbId))
                        )
                        .CurrentSessionContext(_sessionContext);

                    log4net.Config.XmlConfigurator.Configure();
                    var filter = new log4net.Filter.LoggerMatchFilter();
                    filter.LoggerToMatch = "NHibernate.SQL";
                    filter.AcceptOnMatch = true;

                    var filterDeny = new log4net.Filter.DenyAllFilter();

                    var appender = new log4net.Appender.DebugAppender
                    {
                        Layout = new log4net.Layout.SimpleLayout(),
                        Name = "NHibernate.SQL",
                        Threshold = log4net.Core.Level.Debug
                    };

                    appender.AddFilter(filter);
                    appender.AddFilter(filterDeny);
                    log4net.Config.BasicConfigurator.Configure(appender);

                    ModelMapper _modelMapper = new ModelMapper();
                    if (dbId == "APL")
                    {
                        Assembly _assembly = Assembly.Load("APLBackendDB");
                        configuration.Mappings(m => m.FluentMappings.AddFromAssembly(_assembly));
                    }
                    else if (dbId == "FHG")
                    {
                        Assembly _assembly = Assembly.Load("APLFHGDB");
                        configuration.Mappings(m => m.FluentMappings.AddFromAssembly(_assembly));
                    }

                    SessionFactoryLib[dbId] = configuration.BuildSessionFactory();
                }
            }
            return SessionFactoryLib[dbId];
        }