Exemplo n.º 1
0
        /*********
        ** Public methods
        *********/
        /****
        ** Initialization
        ****/
        /// <summary>Construct an instance.</summary>
        /// <param name="logPath">The log file path to write.</param>
        /// <param name="colorConfig">The colors to use for text written to the SMAPI console.</param>
        /// <param name="writeToConsole">Whether to output log messages to the console.</param>
        /// <param name="isVerbose">Whether verbose logging is enabled. This enables more detailed diagnostic messages than are normally needed.</param>
        /// <param name="isDeveloperMode">Whether to enable full console output for developers.</param>
        /// <param name="getScreenIdForLog">Get the screen ID that should be logged to distinguish between players in split-screen mode, if any.</param>
        public LogManager(string logPath, ColorSchemeConfig colorConfig, bool writeToConsole, bool isVerbose, bool isDeveloperMode, Func <int?> getScreenIdForLog)
        {
            // init construction logic
            this.GetMonitorImpl = name => new Monitor(name, this.IgnoreChar, this.LogFile, colorConfig, isVerbose, getScreenIdForLog)
            {
                WriteToConsole         = writeToConsole,
                ShowTraceInConsole     = isDeveloperMode,
                ShowFullStampInConsole = isDeveloperMode
            };

            // init fields
            this.LogFile        = new LogFileManager(logPath);
            this.Monitor        = this.GetMonitor("SMAPI");
            this.MonitorForGame = this.GetMonitor("game");

            // redirect direct console output
            var output = new InterceptingTextWriter(Console.Out, this.IgnoreChar);

            if (writeToConsole)
            {
                output.OnMessageIntercepted += message => this.HandleConsoleMessage(this.MonitorForGame, message);
            }
            Console.SetOut(output);

            // enable Unicode handling on Windows
            // (the terminal defaults to UTF-8 on Linux/macOS)
#if SMAPI_FOR_WINDOWS
            Console.InputEncoding  = Encoding.Unicode;
            Console.OutputEncoding = Encoding.Unicode;
#endif
        }
Exemplo n.º 2
0
        /*********
        ** Public methods
        *********/
        /****
        ** Initialization
        ****/
        /// <summary>Construct an instance.</summary>
        /// <param name="logPath">The log file path to write.</param>
        /// <param name="colorConfig">The colors to use for text written to the SMAPI console.</param>
        /// <param name="writeToConsole">Whether to output log messages to the console.</param>
        /// <param name="isVerbose">Whether verbose logging is enabled. This enables more detailed diagnostic messages than are normally needed.</param>
        /// <param name="isDeveloperMode">Whether to enable full console output for developers.</param>
        public LogManager(string logPath, ColorSchemeConfig colorConfig, bool writeToConsole, bool isVerbose, bool isDeveloperMode)
        {
            // init construction logic
            this.GetMonitorImpl = name => new Monitor(name, this.IgnoreChar, this.LogFile, colorConfig, isVerbose)
            {
                WriteToConsole         = writeToConsole,
                ShowTraceInConsole     = isDeveloperMode,
                ShowFullStampInConsole = isDeveloperMode
            };

            // init fields
            this.LogFile        = new LogFileManager(logPath);
            this.Monitor        = this.GetMonitor("SMAPI");
            this.MonitorForGame = this.GetMonitor("game");

            // redirect direct console output
            var output = new InterceptingTextWriter(Console.Out, this.IgnoreChar);

            if (writeToConsole)
            {
                output.OnMessageIntercepted += message => this.HandleConsoleMessage(this.MonitorForGame, message);
            }
            Console.SetOut(output);
        }