Configured Trace log file via app.config file

This commit is contained in:
miku-666
2023-08-28 21:38:40 +02:00
parent 68705baa49
commit 4f0f0cf66f
4 changed files with 9 additions and 14 deletions

View File

@@ -12,7 +12,11 @@
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
</startup>
<system.diagnostics>
<trace autoflush="true"/>
<trace autoflush="true">
<listeners>
<add name="TraceLogger" type="System.Diagnostics.TextWriterTraceListener" initializeData="trace.log"/>
</listeners>
</trace>
</system.diagnostics>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

View File

@@ -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();

View File

@@ -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));
}
}

View File

@@ -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"))