public static void SetupLogging()
 {
     if (_loggingIsSetup)
       {
     return;
       }
       _loggingIsSetup = true;
       DebugAppender appender = new DebugAppender();
       appender.Layout = new PatternLayout(@"%p %c %m%n");
       log4net.Config.BasicConfigurator.Configure(appender);
 }
        public static IAppender CreateDebugAppender(Level threshold) {
            var layout = new PatternLayout("%date %-5level %logger - %message%newline");
            layout.ActivateOptions();

            var appender = new DebugAppender() {
                Threshold = threshold,
                Layout = layout
            };

            appender.ActivateOptions();

            return appender;
        }
 internal static DebugAppender BuildDebugLog(ListeningLogOptions options)
 {
     var layout = new PatternLayout
     {
         ConversionPattern = options.Pattern
     };
     layout.ActivateOptions();
     var appender = new DebugAppender
     {
         Layout = layout,
         ImmediateFlush = options.ImmediateFlush
     };
     appender.ActivateOptions();
     return appender;
 }
        public static void Configure(string logFilesFolderPath, Log4NetConfigurator configurator)
        {
            if (logFilesFolderPath.StartsWith("~")) logFilesFolderPath = logFilesFolderPath.Substring(1);
            if (logFilesFolderPath.StartsWith("/")) logFilesFolderPath = logFilesFolderPath.Substring(1);

            var hierarchy = (Hierarchy)LogManager.GetRepository();

            hierarchy.Root.Level = Level.Warn;
            hierarchy.Configured = true;

            var patternLayout = new PatternLayout
            {
                ConversionPattern = "%date [%thread] %-5level %logger - %P{Tenant} - %message%newline"
            };
            patternLayout.ActivateOptions();

            var debugFileAppender = BaseFileAppender(patternLayout);
            debugFileAppender.Name = "debug-file";
            debugFileAppender.File = Path.Combine(logFilesFolderPath, "orchard-debug");
            debugFileAppender.ActivateOptions();
            hierarchy.Root.AddAppender(debugFileAppender);

            var errorFileAppender = BaseFileAppender(patternLayout);
            errorFileAppender.Name = "error-file";
            errorFileAppender.File = Path.Combine(logFilesFolderPath, "orchard-error");
            var levelFilter = new LevelRangeFilter { LevelMin = Level.Error };
            levelFilter.ActivateOptions();
            errorFileAppender.AddFilter(levelFilter);
            errorFileAppender.ActivateOptions();
            hierarchy.Root.AddAppender(errorFileAppender);

            var simpleLayout = new SimpleLayout();
            simpleLayout.ActivateOptions();
            var debuggerAppender = new DebugAppender();
            debuggerAppender.Name = "debugger";
            debuggerAppender.ImmediateFlush = true;
            debuggerAppender.Layout = simpleLayout;
            debuggerAppender.ActivateOptions();
            hierarchy.Root.AddAppender(debuggerAppender);

            GetLogger("Orchard").AddAppender(debuggerAppender);
            GetLogger("Orchard.Localization").Level = Level.Warn;
            GetLogger("NHibernate.Cache").Level = Level.Error;
            GetLogger("NHibernate.AdoNet.AbstractBatcher").Level = Level.Off;
            GetLogger("NHibernate.Util.ADOExceptionReporter").Level = Level.Off;

            configurator(hierarchy);
        }
        public static void Init()
        {
            //var file = new FileInfo("output.log");
            //var appender = new FileAppender
            //                {
            //                    AppendToFile = false,
            //                    File = file.FullName,
            //                    Layout = new SimpleLayout()
            //                };

            var appender = new DebugAppender
            {
                Layout = new SimpleLayout()
            };

            log4net.Config.BasicConfigurator.Configure(appender);
        }
Exemple #6
0
 static TestBase()
 {
     DebugAppender a = new DebugAppender();
     a.Layout = new SimpleLayout();
     log4net.Config.BasicConfigurator.Configure(a);
 }
        /// <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];
        }