<commit_before>﻿using System;
using System.Configuration;
using System.Runtime.CompilerServices;
using Rock.Immutable;

namespace Rock.Logging.Library
{
    public static class LibraryLogger
    {
        private static readonly Semimutable<ILibraryLogger> _current = new Semimutable<ILibraryLogger>(() => NullLibraryLogger.Instance);
        private static readonly Semimutable<bool> _isDebugEnabled = new Semimutable<bool>(GetDefaultIsDebugEnabled);

        public static ILibraryLogger Current
        {
            get { return _current.Value; }
        }

        public static void SetCurrent(ILibraryLogger value)
        {
            _current.Value = value ?? NullLibraryLogger.Instance;
        }

        public static bool IsEnabled
        {
            get { return Current != NullLibraryLogger.Instance; }
        }

        public static bool IsDebugEnabled
        {
            get { return _isDebugEnabled.Value; }
            set { _isDebugEnabled.Value = value; }
        }

        private static bool GetDefaultIsDebugEnabled()
        {
            var isDebugEnabledString = ConfigurationManager.AppSettings["Rock.Logging.Library.LibraryLogger.IsDebugEnabled"];

            if (!string.IsNullOrEmpty(isDebugEnabledString))
            {
                bool isDebugEnabled;
                return bool.TryParse(isDebugEnabledString, out isDebugEnabled) && isDebugEnabled;
            }

            return false;
        }

        public static void Log(
            string message,
            string libraryId = null,
            [CallerMemberName] string callerMemberName = null,
            [CallerFilePath] string callerFilePath = null,
            [CallerLineNumber] int callerLineNumber = 0)<commit_msg>Add hook to load library logger from configuration.<commit_after>﻿using System;
using System.Configuration;
using System.Runtime.CompilerServices;
using Rock.Immutable;

namespace Rock.Logging.Library
{
    public static class LibraryLogger
    {
        private static readonly Semimutable<ILibraryLogger> _current = new Semimutable<ILibraryLogger>(GetDefaultLibraryLogger);
        private static readonly Semimutable<bool> _isDebugEnabled = new Semimutable<bool>(GetDefaultIsDebugEnabled);

        public static ILibraryLogger Current
        {
            get { return _current.Value; }
        }

        public static void SetCurrent(ILibraryLogger value)
        {
            _current.Value = value ?? GetDefaultLibraryLogger();
        }

        public static bool IsEnabled
        {
            get { return Current != NullLibraryLogger.Instance; }
        }

        public static bool IsDebugEnabled
        {
            get { return _isDebugEnabled.Value; }
            set { _isDebugEnabled.Value = value; }
        }

        private static ILibraryLogger GetDefaultLibraryLogger()
        {
            // TODO: Attempt to load from configuration.

            return NullLibraryLogger.Instance;
        }

        private static bool GetDefaultIsDebugEnabled()
        {
            var isDebugEnabledString = ConfigurationManager.AppSettings["Rock.Logging.Library.LibraryLogger.IsDebugEnabled"];

            if (!string.IsNullOrEmpty(isDebugEnabledString))
            {
                bool isDebugEnabled;
                return bool.TryParse(isDebugEnabledString, out isDebugEnabled) && isDebugEnabled;
            }

            return false;
        }

        public static void Log(
            string message,
            string libraryId = null,
            [CallerMemberName] string callerMemberName = null,
            [CallerFilePath] string callerFilePath = null,
            [CallerLineNumber] int callerLineNumber = 0)
{'fraction_non_alphanumeric': 0.0668651867893882, 'fraction_numerical': 0.0005414185165132648, 'mean_word_length': 2.269911504424779, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 12, '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': '2546226', 'n_tokens_mistral': 893, 'n_tokens_neox': 858, 'n_words': 219}