<commit_before>namespace chocolatey.infrastructure.logging
{
    using System.IO;
    using System.Reflection;
    using app;
    using log4net;
    using log4net.Appender;
    using log4net.Config;
    using log4net.Core;
    using log4net.Layout;
    using log4net.Repository;
    using log4net.Repository.Hierarchy;

    public sealed class Log4NetAppenderConfiguration
    {
        private static readonly log4net.ILog _logger = LogManager.GetLogger(typeof (Log4NetAppenderConfiguration));

        private static bool _alreadyConfiguredFileAppender;

        /// <summary>
        ///   Pulls xmlconfiguration from embedded location and applies it. Then it configures a file appender to the specified output directory.
        /// </summary>
        /// <param name="outputDirectory">The output directory.</param>
        public static void configure(string outputDirectory)
        {
            Assembly assembly = Assembly.GetExecutingAssembly();
            Stream xmlConfigStream = assembly.get_manifest_stream(ApplicationParameters.Log4NetConfigurationResource);

            XmlConfigurator.Configure(xmlConfigStream);
            set_file_appender(outputDirectory);

            _logger.DebugFormat("Configured {0} from assembly {1}", ApplicationParameters.Log4NetConfigurationResource, assembly.FullName);
        }

        /// <summary>
        ///   Adds a file appender to all current loggers. Only runs one time.
        /// </summary>
        /// <param name="outputDirectory">The output directory.</param>
        private static void set_file_appender(string outputDirectory)
        {
            if (!_alreadyConfiguredFileAppender)
            {
                _alreadyConfiguredFileAppender = true;

                var layout = new PatternLayout
                    {
                        ConversionPattern = "%date [%-5level] - %message%newline"
                    };
                layout.ActivateOptions();

                var lockingModel = new FileAppender.MinimalLock();

                var app = new RollingFileAppender
                    {
                        Name = "{0}.changes.log.appender".format_with(ApplicationParameters.Name),
                        File = Path.Combine(Path.GetFullPath(outputDirectory), ApplicationParameters.LoggingFile),
                        Layout = layout,
                        AppendToFile = true,
                        RollingStyle = RollingFileAppender.RollingMode.Size,
                        MaxFileSize = 1024*1024,
                        MaxSizeRollBackups = 10,
                        LockingModel = lockingModel,
                    };
                app.ActivateOptions();

                ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetCallingAssembly());
                foreach (ILogger log in logRepository.GetCurrentLoggers())
                {
                    var logger = log as Logger;
                    logger.AddAppender(app);
                }
            }<commit_msg>(logging) attempting to remove background craziness from mono<commit_after>namespace chocolatey.infrastructure.logging
{
    using System;
    using System.IO;
    using System.Reflection;
    using app;
    using log4net;
    using log4net.Appender;
    using log4net.Config;
    using log4net.Core;
    using log4net.Layout;
    using log4net.Repository;
    using log4net.Repository.Hierarchy;
    using platforms;

    public sealed class Log4NetAppenderConfiguration
    {
        private static readonly log4net.ILog _logger = LogManager.GetLogger(typeof(Log4NetAppenderConfiguration));

        private static bool _alreadyConfiguredFileAppender;

        /// <summary>
        ///   Pulls xmlconfiguration from embedded location and applies it. Then it configures a file appender to the specified output directory.
        /// </summary>
        /// <param name="outputDirectory">The output directory.</param>
        public static void configure(string outputDirectory)
        {
            Assembly assembly = Assembly.GetExecutingAssembly();
            Stream xmlConfigStream = assembly.get_manifest_stream(ApplicationParameters.Log4NetConfigurationResource);

            XmlConfigurator.Configure(xmlConfigStream);
            set_file_appender(outputDirectory);

            remove_background_color_from_non_windows();

            _logger.DebugFormat("Configured {0} from assembly {1}", ApplicationParameters.Log4NetConfigurationResource, assembly.FullName);
        }

        private static void remove_background_color_from_non_windows()
        {
            if (platforms.Platform.get_platform() == PlatformType.Windows) return;

            ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetCallingAssembly());
            logRepository.Threshold = Level.Debug;
            foreach (IAppender appender in logRepository.GetAppenders())
            {
                var consoleAppender = appender as ManagedColoredConsoleAppender;
                if (consoleAppender != null)
                {
                    var mapping = new ManagedColoredConsoleAppender.LevelColors
                        {
                            ForeColor = ConsoleColor.Green,
                            Level = Level.Info
                        };
                    mapping.ActivateOptions();

                    consoleAppender.AddMapping(mapping);
                }
            }
        }

        /// <summary>
        ///   Adds a file appender to all current loggers. Only runs one time.
        /// </summary>
        /// <param name="outputDirectory">The output directory.</param>
        private static void set_file_appender(string outputDirectory)
        {
            if (!_alreadyConfiguredFileAppender)
            {
                _alreadyConfiguredFileAppender = true;

                var layout = new PatternLayout
                    {
                        ConversionPattern = "%date [%-5level] - %message%newline"
                    };
                layout.ActivateOptions();

                var lockingModel = new FileAppender.MinimalLock();

                var app = new RollingFileAppender
                    {
                        Name = "{0}.changes.log.appender".format_with(ApplicationParameters.Name),
                        File = Path.Combine(Path.GetFullPath(outputDirectory), ApplicationParameters.LoggingFile),
                        Layout = layout,
                        AppendToFile = true,
                        RollingStyle = RollingFileAppender.RollingMode.Size,
                        MaxFileSize = 1024 * 1024,
                        MaxSizeRollBackups = 10,
                        LockingModel = lockingModel,
                    };
                app.ActivateOptions();

                ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetCallingAssembly());
                foreach (ILogger log in logRepository.GetCurrentLoggers())
                {
                    var logger = log as Logger;
                    if (logger != null)
                    {
                        logger.AddAppender(app);
                    }
                }
            }
{'fraction_non_alphanumeric': 0.07340469901292923, 'fraction_numerical': 0.007229250660364243, 'mean_word_length': 1.7829787234042553, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6273219', 'n_tokens_mistral': 1722, 'n_tokens_neox': 1598, 'n_words': 367}