Esempio n. 1
0
 public static void RemoveConsoleHandle(ConsoleExitHandler handler)
 {
     if (SetConsoleCtrlHandler(handler, false))
     {
         Log.Verbose(nameof(Console), $"Removed {handler?.Method.Name} to the console handlers");
     }
     else
     {
         Log.Error(nameof(Console), $"Could not remove handler errorcode: {GetLastError()}");
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Creates a new instance of the <see cref="ConsoleLogger"/> class with a specified output type.
 /// </summary>
 /// <param name="type"> The output type of the logger. </param>
 /// <param name="suppressConsoleResize"> Whether to suppress the console buffer from getting resized. </param>
 public ConsoleLogger(LogOutputType type = LogOutputType.ThreadTime, bool suppressConsoleResize = false)
 {
     Log.AddLogger(this);
     this.type = type;
     if (hndlr == null)
     {
         AddConsoleHandle(hndlr += OnConsoleExit);
     }
     if (!suppressConsoleResize)
     {
         BufferHeight = ExtraMath.Clamp(BufferHeight << 2, MIN_SIZE, MAX_SIZE);
         BufferWidth  = ExtraMath.Clamp(BufferWidth << 2, MIN_SIZE, MAX_SIZE);
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Disposes the managed and unmanaged data of the <see cref="ConsoleLogger"/>.
        /// </summary>
        /// <param name="disposing"> Whether the global log should be disposed. </param>
        protected virtual void Dispose(bool disposing)
        {
            if (!(Disposed || Disposing))
            {
                Disposing = true;
                Log.RemoveLogger();

                if (hndlr != null)
                {
                    RemoveConsoleHandle(hndlr);
                    hndlr -= OnConsoleExit;
                }
                if (updThread != null)
                {
                    updThread.Dispose();
                }

                Disposing = false;
                Disposed  = true;
            }
        }
Esempio n. 4
0
 private static extern bool SetConsoleCtrlHandler(ConsoleExitHandler handler, bool add);