/// <summary>
        /// Sets up the logging facility for the Plugin, which is powered by .NET
        /// </summary>
        void ConfigureLogging() {

            //Create a rolling log file in the MediaPortal log folder
            log4net.Appender.RollingFileAppender rfa = new log4net.Appender.RollingFileAppender();
            rfa.File = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), @"Team MediaPortal\MediaPortal\log\AcidLookup.log");
            rfa.MaxFileSize = 10 * 1024 * 1024;
            rfa.MaxSizeRollBackups = 5;
            rfa.Layout = new log4net.Layout.PatternLayout("%date [%thread] %-5level %logger - %message%newline");

            //add a log match filter to our appender above
            //that will only log AcidLookupPlugin.* loggers
            LoggerMatchFilter sourceFilter = new LoggerMatchFilter();
            sourceFilter.LoggerToMatch = "AcidLookupPlugin";
            rfa.AddFilter(sourceFilter);
            // now add the deny all filter to end of the chain
            DenyAllFilter denyAllFilter = new DenyAllFilter();
            rfa.AddFilter(denyAllFilter);
            // activate the options
            rfa.ActivateOptions();

            ((Logger)log4net.LogManager.GetLogger("AcidLookupPlugin").Logger).AddAppender(rfa);

            //Some plugins may already be using log4net so
            //don't configure it unless it hasn't been configured before
            if (!log4net.LogManager.GetRepository().Configured) {
                log4net.Config.BasicConfigurator.Configure();
            }

            //drop the NHibernate level to Notice
            ((Logger)log4net.LogManager.GetLogger("NHibernate").Logger).Level = Level.Notice;
        }
Example #2
0
        // Create a new file appender
        public static RollingFileAppender CreateFileAppender(LoggerConfigurationElement element)
        {
            var appender = new RollingFileAppender();
            appender.Name = element.LoggerName;
            appender.File = element.Filename;
            appender.AppendToFile = true;
            appender.RollingStyle = RollingFileAppender.RollingMode.Composite;
            appender.MaximumFileSize = element.MaximumFileSize;
            appender.MaxSizeRollBackups = element.MaxSizeRollBackups;
            appender.PreserveLogFileNameExtension = element.PreserveLogFileNameExtension;
            appender.DatePattern = element.DatePattern;

            var layout = new PatternLayout();
            layout.ConversionPattern = "%message";
            layout.ActivateOptions();

            var filter = new LoggerMatchFilter();
            filter.LoggerToMatch = element.LoggerName;
            filter.ActivateOptions();

            var denyAllFilter = new DenyAllFilter();
            denyAllFilter.ActivateOptions();

            appender.AddFilter(filter);
            appender.AddFilter(denyAllFilter);

            appender.Layout = layout;
            appender.ActivateOptions();

            return appender;
        }
Example #3
0
        static void ConfigureLogging(bool verbose)
        {
            var consoleAppender = new log4net.Appender.ConsoleAppender();
            consoleAppender.Layout = new log4net.Layout.PatternLayout("[%date{yyyy-MM-dd HH:mm:ss}] %-5p %c{1} - %m%n");

            if (!verbose) {
                var filter = new LoggerMatchFilter();
                filter.AcceptOnMatch = true;
                filter.LoggerToMatch = typeof(Program).ToString();
                consoleAppender.AddFilter(filter);

                consoleAppender.AddFilter(new DenyAllFilter());
            }

            log4net.Config.BasicConfigurator.Configure(consoleAppender);
        }
        private static IAppender CreateConsoleAppender(LogMessage.SeverityType severity) {
            var appender = new ColoredConsoleAppender();
            appender.AddMapping(new ColoredConsoleAppender.LevelColors {
                ForeColor = ColoredConsoleAppender.Colors.Red,
                Level = Level.Error,
            });
            appender.AddMapping(new ColoredConsoleAppender.LevelColors {
                ForeColor = ColoredConsoleAppender.Colors.Green,
                Level = Level.Debug,
            });
            appender.AddMapping(new ColoredConsoleAppender.LevelColors {
                ForeColor = ColoredConsoleAppender.Colors.White,
                Level = Level.Info,
            });

            appender.Layout = new PatternLayout(LogPattern);
            appender.Name = "Console";
            appender.Threshold = TranslateLevel(severity);
            appender.ActivateOptions();

            var filter = new LoggerMatchFilter {AcceptOnMatch = false, LoggerToMatch = "NHibernate"};
            appender.AddFilter(filter);
            filter = new LoggerMatchFilter {AcceptOnMatch = false, LoggerToMatch = "NHibernate.SQL"};
            appender.AddFilter(filter);

            return appender;
        }
Example #5
0
		static void BootstrapLogger()
		{
            Logger.UseLogger(new Log4NetLogger());

			_appender = new ConsoleAppender();
			_appender.Threshold = Level.Info;
			_appender.Layout = new PatternLayout("%m%n");

			var filter = new LoggerMatchFilter();
			filter.AcceptOnMatch = false;
			filter.LoggerToMatch = "MassTransit";

			_appender.AddFilter(filter);


			BasicConfigurator.Configure(_appender);
		}