<commit_before>﻿/*
 * Author: <NAME> (<EMAIL>)
 * Date: 11/09/2014
 * License: MIT (http://opensource.org/licenses/MIT)
 * GitHub: https://github.com/ivanpointer/NuLog
 */

using NuLog.Configuration;
using NuLog.Configuration.Layouts;
using NuLog.Configuration.Targets;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NuLog.Samples.Samples.S3_4_TextFileTarget
{
    /// <summary>
    /// An example showing the text file target in action.  The narration of this sample
    /// can be found at:
    /// https://github.com/ivanpointer/NuLog/wiki/3.4-Text-File-Target
    /// </summary>
    public class TextFileTargetSample : SampleBase
    {

        #region Sample Wiring

        // Wiring for the sample program (menu wiring)
        public TextFileTargetSample(string section, string sample) : base(section, sample) { }

        #endregion

        // Logging Example
        public override void ExecuteSample(Arguments args)
        {
            ExecuteJSON();

            ExecuteRuntime();
        }

        // Example using JSON configuration
        private void ExecuteJSON()
        {
            LoggerFactory.Initialize("Samples/S3_4_TextFileTarget/NuLog.json");
            var jsonLogger = LoggerFactory.GetLogger();
            jsonLogger.LogNow("Hello from JSON config");
        }

        // Example using runtime configuration
        private void ExecuteRuntime()
        {
            int KB = 1024 ^ 2;

            var config = LoggingConfigBuilder.CreateLoggingConfig()
                .AddTarget(TextFileTargetConfigBuilder.Create()
                    .SetLayoutConfig("Runtime: ${Message}\r\n")

                    .SetFileName("sample.log")
                    .SetOldFileNamePattern("sample{0:.yyyy.MM.dd.hh.mm.ss}.log")

                    .SetRolloverPolicy(RolloverPolicy.Size)
                    .SetRolloverTrigger(1 * KB)

                    //.SetRolloverPolicy(RolloverPolicy.Day)
                    //.SetRolloverTrigger(2)

                    .SetOldFileLimit(5)
                    .SetCompressOldFiles(true)
                    .SetCompressionLevel(3)
                    .SetCompressionPassword("<PASSWORD>")
                    
                    .Build());

            LoggerFactory.Initialize(config);
            var runtimeLogger = LoggerFactory.GetLogger();
            runtimeLogger.LogNow("Hello from runtime config");
        }
    }
}
<commit_msg>Cleaned up sample a bit.<commit_after>﻿/*
 * Author: <NAME> (<EMAIL>)
 * Date: 11/09/2014
 * License: MIT (http://opensource.org/licenses/MIT)
 * GitHub: https://github.com/ivanpointer/NuLog
 */

using NuLog.Configuration;
using NuLog.Configuration.Targets;

namespace NuLog.Samples.Samples.S3_4_TextFileTarget
{
    /// <summary>
    /// An example showing the text file target in action.  The narration of this sample
    /// can be found at:
    /// https://github.com/ivanpointer/NuLog/wiki/3.4-Text-File-Target
    /// </summary>
    public class TextFileTargetSample : SampleBase
    {

        #region Sample Wiring

        // Wiring for the sample program (menu wiring)
        public TextFileTargetSample(string section, string sample) : base(section, sample) { }

        #endregion

        // Logging Example
        public override void ExecuteSample(Arguments args)
        {
            ExecuteJSON();

            ExecuteRuntime();
        }

        // Example using JSON configuration
        private void ExecuteJSON()
        {
            LoggerFactory.Initialize("Samples/S3_4_TextFileTarget/NuLog.json");
            var jsonLogger = LoggerFactory.GetLogger();
            jsonLogger.LogNow("Hello from JSON config");
        }

        // Example using runtime configuration
        private void ExecuteRuntime()
        {
            int KB = 1024 ^ 2;

            var config = LoggingConfigBuilder.CreateLoggingConfig()
                .AddTarget(TextFileTargetConfigBuilder.Create()
                    .SetLayoutConfig("Runtime: ${Message}\r\n")

                    .SetFileName("sample.log")
                    .SetOldFileNamePattern("sample{0:.yyyy.MM.dd.hh.mm.ss}.log")

                    .SetRolloverPolicy(RolloverPolicy.Size)
                    .SetRolloverTrigger(1 * KB)

                    //.SetRolloverPolicy(RolloverPolicy.Day)
                    //.SetRolloverTrigger(2)

                    .SetOldFileLimit(5)
                    .SetCompressOldFiles(true)
                    .SetCompressionLevel(3)
                    .SetCompressionPassword("<PASSWORD>")
                    
                    .Build());

            LoggerFactory.Initialize(config);
            var runtimeLogger = LoggerFactory.GetLogger();
            runtimeLogger.LogNow("Hello from runtime config");
        }
    }
}

{'fraction_non_alphanumeric': 0.10351239669421487, 'fraction_numerical': 0.009917355371900827, 'mean_word_length': 1.8747030878859858, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 4, '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': '4825417', 'n_tokens_mistral': 1346, 'n_tokens_neox': 1225, 'n_words': 258}