<commit_before>﻿namespace SimpleMigrations.Console
{
    // Avoid pain with Console.XXX being assumed to be in SimpleMigrations.Console
    using System;

    /// <summary>
    /// <see cref="ILogger"/> implementation which logs to the console
    /// </summary>
    public class ConsoleLogger : ILogger
    {
        private const int defaultWindowWidth = 80;

        private ConsoleColor foregroundColor;

        /// <summary>
        /// Gets or sets a value indicating whether SQL should be logged
        /// </summary>
        public bool EnableSqlLogging { get; set; } = true;

        private static int GetWindowWidth()
        {
            // This will fail if there's no window, for example

            int width = defaultWindowWidth;
            try
            {
                width = Console.WindowWidth;
            }
            catch { }

            return width;
        }

        /// <summary>
        /// Invoked when a sequence of migrations is started
        /// </summary>
        /// <param name="from">Migration being migrated from</param>
        /// <param name="to">Migration being migrated to</param>
        public void BeginSequence(MigrationData from, MigrationData to)
        {
            this.foregroundColor = Console.ForegroundColor;<commit_msg>Fix crash in ConsoleLogger when running on .net core with no console<commit_after>﻿namespace SimpleMigrations.Console
{
    // Avoid pain with Console.XXX being assumed to be in SimpleMigrations.Console
    using System;

    /// <summary>
    /// <see cref="ILogger"/> implementation which logs to the console
    /// </summary>
    public class ConsoleLogger : ILogger
    {
        private const int defaultWindowWidth = 80;

        private ConsoleColor foregroundColor;

        /// <summary>
        /// Gets or sets a value indicating whether SQL should be logged
        /// </summary>
        public bool EnableSqlLogging { get; set; } = true;

        private static int GetWindowWidth()
        {
            // This will fail if there's no window, for example

            int width = defaultWindowWidth;
            try
            {
                width = Console.WindowWidth;
            }
            catch { }

            // .NET Core apparently returns a width of 0, and when we do 'width - 1' below this crashes
            return Math.Max(1, width);
        }

        /// <summary>
        /// Invoked when a sequence of migrations is started
        /// </summary>
        /// <param name="from">Migration being migrated from</param>
        /// <param name="to">Migration being migrated to</param>
        public void BeginSequence(MigrationData from, MigrationData to)
        {
            this.foregroundColor = Console.ForegroundColor;
{'fraction_non_alphanumeric': 0.0899854862119013, 'fraction_numerical': 0.0025399129172714078, 'mean_word_length': 1.8540372670807452, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, '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': '3824998', 'n_tokens_mistral': 680, 'n_tokens_neox': 653, 'n_words': 238}