Exemple #1
0
        public static void ConfigureCloudWatchLog4net()
        {
            Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository(Assembly.GetEntryAssembly());
            //PatternLayout patternLayout = new PatternLayout
            //{
            //    ConversionPattern = "%-4timestamp [%thread] %-5level %logger %ndc - %message%newline"
            //};
            var splunkLayoutCW = new SplunkLayout()
            {
                LoggedProcessId = "LogTest3Rolling.LAB",
                TimestampFormat = "yyyy-MM-ddTHH:mm:ss.fffZ",
                WithTimeStamp   = false,
            };

            splunkLayoutCW.ActivateOptions();

            //You should be able create any appender and load it into the LogManager which
            //would allow you to drop the log4net.config
            AWSAppender cWappender = new AWSAppender
            {
                Name              = "StartupLogger",
                Layout            = splunkLayoutCW,
                BatchPushInterval = new TimeSpan(0, 0, 0, 5, 0),
                Threshold         = Level.Debug,
                // Set log group and region. Assume credentials will be found using the default profile or IAM credentials.
                LogGroup = "Logging.Startup",
                Region   = "us-east-1"
            };
            var cwFilter = new log4net.Filter.LoggerMatchFilter()
            {
                LoggerToMatch = "LogTest3.CloudWatchFilter",
                AcceptOnMatch = true
            };
            var non = new log4net.Filter.DenyAllFilter();

            non.ActivateOptions();
            cwFilter.ActivateOptions();
            cWappender.AddFilter(cwFilter);
            cWappender.AddFilter(non);
            cWappender.ActivateOptions();
            hierarchy.Root.AddAppender(cWappender);
        }
Exemple #2
0
        public static void ConfigureLog4net()
        {
            Hierarchy hierarchy      = (Hierarchy)LogManager.GetRepository(Assembly.GetEntryAssembly());
            var       splunkLayoutS3 = new SplunkLayout()
            {
                LoggedProcessId = "LogTest3Rolling.LAB",
                TimestampFormat = "yyyy-MM-ddTHH:mm:ss.fffZ",
                ObjectFormat    = "html",
                Header          = "<h1>Adding a Header???</h1>",
                Footer          = "<h3>Also a footer??? Oh la la</h3>"
            };

            splunkLayoutS3.ActivateOptions();
            var s3appender = new S3Appender()
            {
                Name               = "S3NoConfigAppender",
                Layout             = splunkLayoutS3,
                Threshold          = Level.Debug,
                BufferSize         = 5,
                LibraryLogFileName = "_Log_NoConfigError",
                BucketName         = "logtest2bucketpoc",
                LogDirectory       = "WhatIsThis",
                FilePrefix         = "S3Appender_html",
                FileExtension      = "html",
            };
            var htmlFilter = new log4net.Filter.LoggerMatchFilter()
            {
                LoggerToMatch = "LogTest3.HtmlFilter",
                AcceptOnMatch = true
            };
            var non = new log4net.Filter.DenyAllFilter();

            non.ActivateOptions();
            htmlFilter.ActivateOptions();
            s3appender.AddFilter(htmlFilter);
            s3appender.AddFilter(non);

            s3appender.ActivateOptions();
            hierarchy.Root.AddAppender(s3appender);
        }
Exemple #3
0
        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");
        }
        /// <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];
        }