예제 #1
0
        /// <summary>
        /// Sets up wrapper to work with log4net
        /// </summary>
        private void Setup()
        {
            _awsAppender = CreateAppender(_awsCredentials);
            var hierarchy = (Hierarchy)_loggerAdapter.Logger.Repository;
            var logger    = hierarchy.GetLogger(nameof(SmartApartmentLogger)) as log4net.Repository.Hierarchy.Logger;

            logger.AddAppender(_awsAppender);
        }
예제 #2
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);
        }
예제 #3
0
        private static AWSAppender CreateAppender(AWSCredentials credentials)
        {
            var patternLayout = new PatternLayout
            {
                ConversionPattern = logLayoutPattern
            };

            patternLayout.ActivateOptions();

            var appender = new AWSAppender
            {
                Layout      = patternLayout,
                Credentials = credentials,
                LogGroup    = logGroup,
                Region      = awsRegion
            };

            appender.ActivateOptions();
            return(appender);
        }
예제 #4
0
        static void ConfigureLog4net()
        {
            Hierarchy     hierarchy     = (Hierarchy)LogManager.GetRepository();
            PatternLayout patternLayout = new PatternLayout();

            patternLayout.ConversionPattern = "%-4timestamp [%thread] %-5level %logger %ndc - %message%newline";
            patternLayout.ActivateOptions();

            AWSAppender appender = new AWSAppender();

            appender.Layout = patternLayout;

            // Set log group and region. Assume credentials will be found using the default profile or IAM credentials.
            appender.LogGroup = "Log4net.ProgrammaticConfigurationExample";
            appender.Region   = "us-east-1";

            appender.ActivateOptions();
            hierarchy.Root.AddAppender(appender);

            hierarchy.Root.Level = Level.All;
            hierarchy.Configured = true;
        }