From 4f0f0cf66f383ee40ce5b7b288aff2f9930dffae Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Mon, 28 Aug 2023 21:38:40 +0200 Subject: [PATCH] Configured Trace log file via app.config file --- PCK-Studio/App.config | 6 +++++- PCK-Studio/Internal/ApplicationScope.cs | 1 - PCK-Studio/Internal/Profiler.cs | 13 +++---------- PCK-Studio/Program.cs | 3 +-- 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/PCK-Studio/App.config b/PCK-Studio/App.config index db7ee6ab..fff538b6 100644 --- a/PCK-Studio/App.config +++ b/PCK-Studio/App.config @@ -12,7 +12,11 @@ - + + + + + diff --git a/PCK-Studio/Internal/ApplicationScope.cs b/PCK-Studio/Internal/ApplicationScope.cs index 171abb74..361ad2e4 100644 --- a/PCK-Studio/Internal/ApplicationScope.cs +++ b/PCK-Studio/Internal/ApplicationScope.cs @@ -19,7 +19,6 @@ namespace PckStudio.Internal internal static void Initialize() { - Profiler.Configure(Debug.Listeners[0]); Profiler.Start(); { _entityImages ??= Resources.entities_sheet.SplitHorizontal(32).ToArray(); diff --git a/PCK-Studio/Internal/Profiler.cs b/PCK-Studio/Internal/Profiler.cs index 1c503d26..f9daff27 100644 --- a/PCK-Studio/Internal/Profiler.cs +++ b/PCK-Studio/Internal/Profiler.cs @@ -28,19 +28,12 @@ namespace PckStudio.Internal internal static class Profiler { private static Stopwatch _stopwatch = new Stopwatch(); - private static TraceListener _listener; - - [Conditional("DEBUG")] - internal static void Configure(TraceListener listener) - { - _listener = listener; - } [Conditional("DEBUG")] internal static void Start([CallerMemberName] string caller = default!, [CallerFilePath] string source = default!, [CallerLineNumber] int line = default!) { - _listener?.WriteLine($"Stopwatch starts", category: nameof(Profiler)); - _listener?.WriteLine($"{source}@{caller}:{line}", category: nameof(Profiler)); + Debug.WriteLine($"Stopwatch starts", category: nameof(Profiler)); + Debug.WriteLine($"{source}@{caller}:{line}", category: nameof(Profiler)); _stopwatch.Restart(); } @@ -48,7 +41,7 @@ namespace PckStudio.Internal internal static void Stop([CallerMemberName] string caller = default!, [CallerFilePath] string source = default!, [CallerLineNumber] int line = default!) { _stopwatch.Stop(); - _listener?.WriteLine($"{caller} took {_stopwatch.ElapsedMilliseconds}ms", category: nameof(Profiler)); + Debug.WriteLine($"{caller} took {_stopwatch.ElapsedMilliseconds}ms", category: nameof(Profiler)); } } diff --git a/PCK-Studio/Program.cs b/PCK-Studio/Program.cs index c14667e5..644b6c70 100644 --- a/PCK-Studio/Program.cs +++ b/PCK-Studio/Program.cs @@ -23,9 +23,8 @@ namespace PckStudio [STAThread] static void Main(string[] args) { - using var traceFile = File.OpenWrite(Path.Combine(Application.StartupPath, "tarce.log")); - Trace.Listeners.Add(new TextWriterTraceListener(traceFile)); ApplicationScope.Initialize(); + Trace.TraceInformation("Startup"); RPC.Initialize(); MainInstance = new MainForm(); if (args.Length > 0 && File.Exists(args[0]) && args[0].EndsWith(".pck"))