<commit_before>// 
// Copyright (c) 2004 <NAME> <<EMAIL>>
// 
// All rights reserved.
// 
// Redistribution and use in source and binary forms, with or without 
// modification, are permitted provided that the following conditions 
// are met:
// 
// * Redistributions of source code must retain the above copyright notice, 
//   this list of conditions and the following disclaimer. 
// 
// * Redistributions in binary form must reproduce the above copyright notice,
//   this list of conditions and the following disclaimer in the documentation
//   and/or other materials provided with the distribution. 
// 
// * Neither the name of the <NAME> nor the names of its 
//   contributors may be used to endorse or promote products derived from this
//   software without specific prior written permission. 
// 
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
// THE POSSIBILITY OF SUCH DAMAGE.
// 

using System;
using System.Collections;
using System.Xml;
using System.IO;
using System.Reflection;
using System.Globalization;
using System.Text;

using NLog.Config;

namespace NLog
{
    internal sealed class InternalLogger
    {
        private static LogLevel _logLevel = LogLevel.Info;
        private static bool _logToConsole = false;

        public static LogLevel LogLevel
        {
            get { return _logLevel; }
            set { _logLevel = value; }
        }

        public static bool LogToConsole
        {
            get { return _logToConsole; }
            set { _logToConsole = value; }
        }

        public static string LogFile
        {
            get { return _logFile; }
            set { _logFile = value; }
        }

        private static string _logFile = null;

#if !NETCF
        static InternalLogger()
        {
            try
            {
                if (Environment.GetEnvironmentVariable("NLOG_INTERNAL_LOG_TO_CONSOLE") != null) {
                    LogToConsole = true;
                }
                if (Environment.GetEnvironmentVariable("NLOG_INTERNAL_LOG_LEVEL") != null) {
                    LogLevel = Logger.LogLevelFromString(Environment.GetEnvironmentVariable("NLOG_INTERNAL_LOG_LEVEL"));
                }
                _logFile = Environment.GetEnvironmentVariable("NLOG_INTERNAL_LOG_FILE");
                Info("NLog internal logger initialized.");
            }
            catch
            {
            }
        }
#endif

        private InternalLogger()
        {
        }

        private static void Write(LogLevel level, IFormatProvider formatProvider, string message, object[] args)
        {
            if (level < _logLevel)
                return;

            if (_logFile == null && !_logToConsole)
                return;

            try {
                string formattedMessage = message;
                if (args != null)
                    formattedMessage = String.Format(formatProvider, message, args);

                StringBuilder builder = new StringBuilder(message.Length + 32);
                builder.Append(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffff", CultureInfo.InvariantCulture));
                builder.Append(" ");
                builder.Append(level.ToString());
                builder.Append(" ");
                builder.Append(formattedMessage);
                string msg = builder.ToString();

                if (_logFile != null) {
                    using (TextWriter textWriter = File.AppendText(_logFile)) {
                        textWriter.WriteLine(msg);
                    }
                }

                if (_logToConsole) {
                    Console.WriteLine(msg);
                }
            }
            catch (Exception) {
            }
        }

        public bool IsDebugEnabled { get { return _logLevel >= LogLevel.Debug; } }
        public bool IsInfoEnabled  { get { return _logLevel >= LogLevel.Info; } }
        public bool IsWarnEnabled  { get { return _logLevel >= LogLevel.Warn; } }
        public bool IsErrorEnabled { get { return _logLevel >= LogLevel.Error; } }
        public bool IsFatalEnabled { get { return _logLevel >= LogLevel.Fatal; } }

        public static void Log(LogLevel level, IFormatProvider formatProvider, string message, params object[] args) 
        {
            Write(level, formatProvider, message, args);
        }

        public static void Log(LogLevel level, string message, params object[] args) 
        {
            Write(level, null, message, args);
        }

        public static void Log(LogLevel level, string message) {
            Write(level, null, message, null);
        }

        public static void Debug(IFormatProvider formatProvider, string message, params object[] args) { Write(LogLevel.Debug, formatProvider, message, args); }
        public static void Debug(string message, params object[] args) { Write(LogLevel.Debug, null, message, args); }
        public static void Debug(string message) {
            Write(LogLevel.Debug, null, message, null);
        }

        public static void Info(IFormatProvider formatProvider, string message, params object[] args) 
        {
            Write(LogLevel.Info, formatProvider, message, args);
        }

        public static void Info(string message, params object[] args) <commit_msg>fixed InternalLogger.IsXXXEnabled<commit_after>// 
// Copyright (c) 2004 <NAME> <<EMAIL>>
// 
// All rights reserved.
// 
// Redistribution and use in source and binary forms, with or without 
// modification, are permitted provided that the following conditions 
// are met:
// 
// * Redistributions of source code must retain the above copyright notice, 
//   this list of conditions and the following disclaimer. 
// 
// * Redistributions in binary form must reproduce the above copyright notice,
//   this list of conditions and the following disclaimer in the documentation
//   and/or other materials provided with the distribution. 
// 
// * Neither the name of the <NAME> nor the names of its 
//   contributors may be used to endorse or promote products derived from this
//   software without specific prior written permission. 
// 
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
// THE POSSIBILITY OF SUCH DAMAGE.
// 

using System;
using System.Collections;
using System.Xml;
using System.IO;
using System.Reflection;
using System.Globalization;
using System.Text;

using NLog.Config;

namespace NLog
{
    internal sealed class InternalLogger
    {
        private static LogLevel _logLevel = LogLevel.Info;
        private static bool _logToConsole = false;

        public static LogLevel LogLevel
        {
            get { return _logLevel; }
            set { _logLevel = value; }
        }

        public static bool LogToConsole
        {
            get { return _logToConsole; }
            set { _logToConsole = value; }
        }

        public static string LogFile
        {
            get { return _logFile; }
            set { _logFile = value; }
        }

        private static string _logFile = null;

#if !NETCF
        static InternalLogger()
        {
            try
            {
                if (Environment.GetEnvironmentVariable("NLOG_INTERNAL_LOG_TO_CONSOLE") != null) {
                    LogToConsole = true;
                }
                if (Environment.GetEnvironmentVariable("NLOG_INTERNAL_LOG_LEVEL") != null) {
                    LogLevel = Logger.LogLevelFromString(Environment.GetEnvironmentVariable("NLOG_INTERNAL_LOG_LEVEL"));
                }
                _logFile = Environment.GetEnvironmentVariable("NLOG_INTERNAL_LOG_FILE");
                Info("NLog internal logger initialized.");
            }
            catch
            {
            }
        }
#endif

        private InternalLogger()
        {
        }

        private static void Write(LogLevel level, IFormatProvider formatProvider, string message, object[] args)
        {
            if (level < _logLevel)
                return;

            if (_logFile == null && !_logToConsole)
                return;

            try {
                string formattedMessage = message;
                if (args != null)
                    formattedMessage = String.Format(formatProvider, message, args);

                StringBuilder builder = new StringBuilder(message.Length + 32);
                builder.Append(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffff", CultureInfo.InvariantCulture));
                builder.Append(" ");
                builder.Append(level.ToString());
                builder.Append(" ");
                builder.Append(formattedMessage);
                string msg = builder.ToString();

                if (_logFile != null) {
                    using (TextWriter textWriter = File.AppendText(_logFile)) {
                        textWriter.WriteLine(msg);
                    }
                }

                if (_logToConsole) {
                    Console.WriteLine(msg);
                }
            }
            catch (Exception) {
            }
        }

        public static bool IsDebugEnabled { get { return _logLevel >= LogLevel.Debug; } }
        public static bool IsInfoEnabled  { get { return _logLevel >= LogLevel.Info; } }
        public static bool IsWarnEnabled  { get { return _logLevel >= LogLevel.Warn; } }
        public static bool IsErrorEnabled { get { return _logLevel >= LogLevel.Error; } }
        public static bool IsFatalEnabled { get { return _logLevel >= LogLevel.Fatal; } }

        public static void Log(LogLevel level, IFormatProvider formatProvider, string message, params object[] args) 
        {
            Write(level, formatProvider, message, args);
        }

        public static void Log(LogLevel level, string message, params object[] args) 
        {
            Write(level, null, message, args);
        }

        public static void Log(LogLevel level, string message) {
            Write(level, null, message, null);
        }

        public static void Debug(IFormatProvider formatProvider, string message, params object[] args) { Write(LogLevel.Debug, formatProvider, message, args); }
        public static void Debug(string message, params object[] args) { Write(LogLevel.Debug, null, message, args); }
        public static void Debug(string message) {
            Write(LogLevel.Debug, null, message, null);
        }

        public static void Info(IFormatProvider formatProvider, string message, params object[] args) 
        {
            Write(LogLevel.Info, formatProvider, message, args);
        }

        public static void Info(string message, params object[] args) 
{'fraction_non_alphanumeric': 0.08103606229699342, 'fraction_numerical': 0.0009994170067460647, 'mean_word_length': 2.1238293444328824, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '2206468', 'n_tokens_mistral': 3058, 'n_tokens_neox': 2846, 'n_words': 1016}