<commit_before>﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using ShellMe.CommandLine.CommandHandling;

namespace ShellMe.CommandLine
{
    class TraceConsole : ITraceConsole, IDisposable
    {
        private readonly IList<IDisposable> _disposables;

        public TraceConsole(IConsole console, ICommand command)
        {
            Console = console;
            Command = command;
            _disposables = new List<IDisposable>();

            TraceableCommand = command as ITraceableCommand;

            if (TraceableCommand != null)
            {
                Trace.AutoFlush = true;
                TraceSource = new TraceSource(command.Name)
                                  {
                                      Switch = new SourceSwitch(Command.Name)
                                                   {
                                                       Level = SourceLevels.All
                                                   }
                                  };


                if (!string.IsNullOrEmpty(TraceableCommand.WriteFile))
                {
                    var listener = new TextWriterTraceListener(TraceableCommand.WriteFile);
                    listener.Filter = new EventTypeFilter(!TraceableCommand.FileLogLevel.Any() ? GetLevel(TraceableCommand.LogLevel) : GetLevel(TraceableCommand.FileLogLevel));
                    TraceSource.Listeners.Add(listener);
                    _disposables.Add(listener);
                }
                if (TraceableCommand.WriteEventLog)
                {
                    var listener = new EventLogTraceListener(Command.Name);
                    listener.Filter = new EventTypeFilter(!TraceableCommand.EventLogLevel.Any() ? GetLevel(TraceableCommand.LogLevel) : GetLevel(TraceableCommand.EventLogLevel));
                    TraceSource.Listeners.Add(listener);
                    _disposables.Add(listener);
                }
            }
        }

        protected ITraceableCommand TraceableCommand { get; private set; }

        protected ICommand Command { get; set; }<commit_msg>Fixed #7 support for dated dirs<commit_after>﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using ShellMe.CommandLine.CommandHandling;

namespace ShellMe.CommandLine
{
    class TraceConsole : ITraceConsole, IDisposable
    {
        private readonly IList<IDisposable> _disposables;

        public TraceConsole(IConsole console, ICommand command)
        {
            Console = console;
            Command = command;
            _disposables = new List<IDisposable>();

            TraceableCommand = command as ITraceableCommand;

            if (TraceableCommand != null)
            {
                Trace.AutoFlush = true;
                TraceSource = new TraceSource(command.Name)
                                  {
                                      Switch = new SourceSwitch(Command.Name)
                                                   {
                                                       Level = SourceLevels.All
                                                   }
                                  };


                if (!string.IsNullOrEmpty(TraceableCommand.WriteFile))
                {
                    var fileName = string.Format(TraceableCommand.WriteFile.Replace("{", "{0:"),DateTime.Now);

                    var fileInfo = new FileInfo(fileName);
                    if (fileInfo.Directory != null && !fileInfo.Directory.Exists)
                    {
                        fileInfo.Directory.Create();
                    }

                    var listener = new TextWriterTraceListener(fileName);
                    listener.Filter = new EventTypeFilter(!TraceableCommand.FileLogLevel.Any() ? GetLevel(TraceableCommand.LogLevel) : GetLevel(TraceableCommand.FileLogLevel));
                    TraceSource.Listeners.Add(listener);
                    _disposables.Add(listener);
                }
                if (TraceableCommand.WriteEventLog)
                {
                    var listener = new EventLogTraceListener(Command.Name);
                    listener.Filter = new EventTypeFilter(!TraceableCommand.EventLogLevel.Any() ? GetLevel(TraceableCommand.LogLevel) : GetLevel(TraceableCommand.EventLogLevel));
                    TraceSource.Listeners.Add(listener);
                    _disposables.Add(listener);
                }
            }
        }

        protected ITraceableCommand TraceableCommand { get; private set; }

        protected ICommand Command { get; set; }
{'fraction_non_alphanumeric': 0.0739000427167877, 'fraction_numerical': 0.00042716787697565144, 'mean_word_length': 1.501602564102564, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1453880', 'n_tokens_mistral': 1067, 'n_tokens_neox': 1011, 'n_words': 196}