<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Serilog;
using Serilog.Events;

namespace SerilogWeb.Classic
{
    /// <summary>
    /// The Builder class to create a new SerilogWebClassicConfiguration
    /// </summary>
    public class SerilogWebClassicConfigurationBuilder
    {
        private static readonly Func<HttpContextBase, bool> AlwaysFalse = context => false;
        private static readonly string[] DefaultFilteredOutFormDataKeywords = { "password" };

        private bool IsEnabled { get; set; } = true;

        private LogEventLevel RequestLoggingLevel { get; set; }
        private Func<long, LogEventLevel> RequestElapsedMSLogLevel { get; set; }
        private ILogger CustomLogger { get; set; }
        private Func<HttpContextBase, bool> RequestFilter { get; set; }

        private LogEventLevel FormDataLoggingLevel { get; set; }
        private LogPostedFormDataOption LogPostedFormData { get; set; }
        private Func<HttpContextBase, bool> ShouldLogPostedFormData { get; set; }

        private bool FilterPasswordsInFormData { get; set; }
        private IEnumerable<String> FilteredKeywordsInFormData { get; set; }

        internal SerilogWebClassicConfigurationBuilder()
        {
            Reset();
        }

        internal SerilogWebClassicConfigurationBuilder(SerilogWebClassicConfiguration configToCopy)
        {
            if (configToCopy == null) throw new ArgumentNullException(nameof(configToCopy));
            CustomLogger = configToCopy.CustomLogger;
            IsEnabled = configToCopy.IsEnabled;
            RequestLoggingLevel = configToCopy.RequestLoggingLevel;
            RequestElapsedMSLogLevel = configToCopy.RequestElapsedMSLogLevel;
            RequestFilter = configToCopy.RequestFilter;
            FormDataLoggingLevel = configToCopy.FormDataLoggingLevel;
            LogPostedFormData = configToCopy.LogPostedFormData;
            ShouldLogPostedFormData = configToCopy.ShouldLogPostedFormData;
            FilterPasswordsInFormData = configToCopy.FilterPasswordsInFormData;
            FilteredKeywordsInFormData = configToCopy.FilteredKeywordsInFormData;
        }

        private void Reset()
        {
            CustomLogger = null;
            IsEnabled = true;
            RequestLoggingLevel = LogEventLevel.Information;
            RequestFilter = AlwaysFalse;
            ResetFormDataLogging();
        }

        private void ResetFormDataLogging()
        {
            FormDataLoggingLevel = LogEventLevel.Debug;
            LogPostedFormData = LogPostedFormDataOption.Never;
            ShouldLogPostedFormData = AlwaysFalse;
            FilterPasswordsInFormData = true;
            FilteredKeywordsInFormData = DefaultFilteredOutFormDataKeywords;
        }

        internal SerilogWebClassicConfiguration Build()
        {
            return new SerilogWebClassicConfiguration(
                isEnabled: IsEnabled,
                requestLoggingLevel: RequestLoggingLevel,
                requestElapsedMSLogLevel: RequestElapsedMSLogLevel,
                requestFilter: RequestFilter,
                formDataLoggingLevel: FormDataLoggingLevel,
                customLogger: CustomLogger,
                logPostedFormData: LogPostedFormData,
                shouldLogPostedFormData: ShouldLogPostedFormData,
                filterPasswordsInFormData: FilterPasswordsInFormData,
                filteredKeywordsInFormData: FilteredKeywordsInFormData);
        }

        /// <summary>
        /// Disable the logging module completely. Not log events will be written for incoming Http requests
        /// </summary>
        /// <returns>A configuration object to allow chaining</returns>
        public SerilogWebClassicConfigurationBuilder Disable()
        {
            IsEnabled = false;
            return this;
        }

        /// <summary>
        /// Enable the logging completely so that log events are written for incoming requests.
        /// Is it enabled by default.
        /// </summary>
        /// <returns>A configuration object to allow chaining</returns>
        public SerilogWebClassicConfigurationBuilder Enable()
        {
            IsEnabled = true;
            return this;
        }


        /// <summary>
        /// Configure at which level HTTP requests are logged.
        /// Default is Information
        /// </summary>
        /// <param name="level">The level to override the default value</param>
        /// <returns>A configuration object to allow chaining</returns>
        public SerilogWebClassicConfigurationBuilder LogAtLevel(LogEventLevel level)
        {
            RequestLoggingLevel = level;
            return this;
        }

        /// <summary>
        /// Configure at which level HTTP requests are logged.
        /// Default is Information
        /// </summary>
        /// <param name="level">The level to override the default value</param>
        /// <param name="requestElapsedMSLogLevel">Override the default log level based on the total request time in milliseconds</param>
        /// <returns>A configuration object to allow chaining</returns>
        public SerilogWebClassicConfigurationBuilder LogAtLevel(LogEventLevel level, Func<long, LogEventLevel> requestElapsedMSLogLevel)
        {
            RequestLoggingLevel = level;
            RequestElapsedMSLogLevel = requestElapsedMSLogLevel;

            return this;<commit_msg>Remove param<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Serilog;
using Serilog.Events;

namespace SerilogWeb.Classic
{
    /// <summary>
    /// The Builder class to create a new SerilogWebClassicConfiguration
    /// </summary>
    public class SerilogWebClassicConfigurationBuilder
    {
        private static readonly Func<HttpContextBase, bool> AlwaysFalse = context => false;
        private static readonly string[] DefaultFilteredOutFormDataKeywords = { "password" };

        private bool IsEnabled { get; set; } = true;

        private LogEventLevel RequestLoggingLevel { get; set; }
        private Func<long, LogEventLevel> RequestElapsedMSLogLevel { get; set; }
        private ILogger CustomLogger { get; set; }
        private Func<HttpContextBase, bool> RequestFilter { get; set; }

        private LogEventLevel FormDataLoggingLevel { get; set; }
        private LogPostedFormDataOption LogPostedFormData { get; set; }
        private Func<HttpContextBase, bool> ShouldLogPostedFormData { get; set; }

        private bool FilterPasswordsInFormData { get; set; }
        private IEnumerable<String> FilteredKeywordsInFormData { get; set; }

        internal SerilogWebClassicConfigurationBuilder()
        {
            Reset();
        }

        internal SerilogWebClassicConfigurationBuilder(SerilogWebClassicConfiguration configToCopy)
        {
            if (configToCopy == null) throw new ArgumentNullException(nameof(configToCopy));
            CustomLogger = configToCopy.CustomLogger;
            IsEnabled = configToCopy.IsEnabled;
            RequestLoggingLevel = configToCopy.RequestLoggingLevel;
            RequestElapsedMSLogLevel = configToCopy.RequestElapsedMSLogLevel;
            RequestFilter = configToCopy.RequestFilter;
            FormDataLoggingLevel = configToCopy.FormDataLoggingLevel;
            LogPostedFormData = configToCopy.LogPostedFormData;
            ShouldLogPostedFormData = configToCopy.ShouldLogPostedFormData;
            FilterPasswordsInFormData = configToCopy.FilterPasswordsInFormData;
            FilteredKeywordsInFormData = configToCopy.FilteredKeywordsInFormData;
        }

        private void Reset()
        {
            CustomLogger = null;
            IsEnabled = true;
            RequestLoggingLevel = LogEventLevel.Information;
            RequestFilter = AlwaysFalse;
            ResetFormDataLogging();
        }

        private void ResetFormDataLogging()
        {
            FormDataLoggingLevel = LogEventLevel.Debug;
            LogPostedFormData = LogPostedFormDataOption.Never;
            ShouldLogPostedFormData = AlwaysFalse;
            FilterPasswordsInFormData = true;
            FilteredKeywordsInFormData = DefaultFilteredOutFormDataKeywords;
        }

        internal SerilogWebClassicConfiguration Build()
        {
            return new SerilogWebClassicConfiguration(
                isEnabled: IsEnabled,
                requestLoggingLevel: RequestLoggingLevel,
                requestElapsedMSLogLevel: RequestElapsedMSLogLevel,
                requestFilter: RequestFilter,
                formDataLoggingLevel: FormDataLoggingLevel,
                customLogger: CustomLogger,
                logPostedFormData: LogPostedFormData,
                shouldLogPostedFormData: ShouldLogPostedFormData,
                filterPasswordsInFormData: FilterPasswordsInFormData,
                filteredKeywordsInFormData: FilteredKeywordsInFormData);
        }

        /// <summary>
        /// Disable the logging module completely. Not log events will be written for incoming Http requests
        /// </summary>
        /// <returns>A configuration object to allow chaining</returns>
        public SerilogWebClassicConfigurationBuilder Disable()
        {
            IsEnabled = false;
            return this;
        }

        /// <summary>
        /// Enable the logging completely so that log events are written for incoming requests.
        /// Is it enabled by default.
        /// </summary>
        /// <returns>A configuration object to allow chaining</returns>
        public SerilogWebClassicConfigurationBuilder Enable()
        {
            IsEnabled = true;
            return this;
        }


        /// <summary>
        /// Configure at which level HTTP requests are logged.
        /// Default is Information
        /// </summary>
        /// <param name="level">The level to override the default value</param>
        /// <returns>A configuration object to allow chaining</returns>
        public SerilogWebClassicConfigurationBuilder LogAtLevel(LogEventLevel level)
        {
            RequestLoggingLevel = level;
            return this;
        }

        /// <summary>
        /// Configure at which level HTTP requests are logged.
        /// Default is Information
        /// </summary>
        /// <param name="requestElapsedMSLogLevel">Override the default log level based on the total request time in milliseconds</param>
        /// <returns>A configuration object to allow chaining</returns>
        public SerilogWebClassicConfigurationBuilder LogAtLevel(Func<long, LogEventLevel> requestElapsedMSLogLevel)
        {
            RequestElapsedMSLogLevel = requestElapsedMSLogLevel;
            return this;
{'fraction_non_alphanumeric': 0.06844741235392321, 'fraction_numerical': 0.0, 'mean_word_length': 2.419917538851887, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 63, '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': '6616181', 'n_tokens_mistral': 2645, 'n_tokens_neox': 2568, 'n_words': 648}