Browse Source

Fix preloader logger using standard out

Bepis 6 years ago
parent
commit
c8cc7186b4
2 changed files with 14 additions and 20 deletions
  1. 1 1
      BepInEx/Bootstrap/Preloader.cs
  2. 13 19
      BepInEx/Logging/PreloaderLogWriter.cs

+ 1 - 1
BepInEx/Bootstrap/Preloader.cs

@@ -132,7 +132,7 @@ namespace BepInEx.Bootstrap
                 Logger.Log(LogLevel.Fatal, "Could not run preloader!");
                 Logger.Log(LogLevel.Fatal, ex);
 
-                PreloaderLog.Disable();
+                PreloaderLog.Enabled = false;
 
                 try
                 {

+ 13 - 19
BepInEx/Logging/PreloaderLogWriter.cs

@@ -29,20 +29,20 @@ namespace BepInEx.Logging
         public PreloaderLogWriter(bool redirectConsole)
         {
             IsRedirectingConsole = redirectConsole;
-
-            if (IsRedirectingConsole)
-                stdout = Console.Out;
-
+            
+            stdout = Console.Out;
             traceListener = new LoggerTraceListener(this);
         }
 
         public void Enable()
         {
-            if (Enabled)
+            if (_enabled)
                 return;
 
             if (IsRedirectingConsole)
                 Console.SetOut(this);
+            else
+                Console.SetOut(TextWriter.Null);
 
             Trace.Listeners.Add(traceListener);
 
@@ -51,11 +51,10 @@ namespace BepInEx.Logging
 
         public void Disable()
         {
-            if (!Enabled)
+            if (!_enabled)
                 return;
-
-            if (IsRedirectingConsole)
-                Console.SetOut(stdout);
+            
+            Console.SetOut(stdout);
 
             Trace.Listeners.Remove(traceListener);
 
@@ -66,28 +65,23 @@ namespace BepInEx.Logging
         {
             StringBuilder.Append(value);
 
-            if (IsRedirectingConsole)
-                stdout.Write(value);
-            else
-                Console.Write(value);
+            stdout.Write(value);
         }
 
         public override void Write(string value)
         {
             StringBuilder.Append(value);
 
-            if (IsRedirectingConsole)
-                stdout.Write(value);
-            else
-                Console.Write(value);
+            stdout.Write(value);
         }
 
         protected override void Dispose(bool disposing)
         {
             Disable();
             StringBuilder.Length = 0;
-
-            base.Dispose(disposing);
+            
+            traceListener?.Dispose();
+            traceListener = null;
         }
 
         public override string ToString()