Skip to content

Commit 764aac0

Browse files
authored
Merge pull request #1016 from twpol/feature/std-log/trace-log
Route all logging via Trace #or-std-log
2 parents 934fd3a + 5a94c4e commit 764aac0

File tree

8 files changed

+22
-22
lines changed

8 files changed

+22
-22
lines changed

Source/Orts.Formats.Msts/TrackSectionsFile.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ private void AddPath(STFReader stf, TrackPath path)
344344
}
345345
catch (Exception e)
346346
{
347-
System.Console.WriteLine("Warning: in route tsection.dat " + e.Message);
347+
Trace.WriteLine(new FileLoadException("In route tsection.dat", e));
348348
}
349349
}
350350
public uint NoSections;

Source/Orts.Parsers.Msts/SBR.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static SBR Open(string filename)
6767
else if (headerString.StartsWith("\r\nSIMISA"))
6868
{
6969
// ie us1rd2l1000r10d.s, we are going to allow this but warn
70-
Console.Error.WriteLine("Improper header in " + filename);
70+
Trace.TraceWarning("Improper header in " + filename);
7171
fb.Read(buffer, 0, 4);
7272
}
7373
else if (!headerString.StartsWith("SIMISA@@"))

Source/Orts.Simulation/MultiPlayer/ClientComm.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ public void Receive(object client)
133133
}
134134
catch (Exception e)
135135
{
136-
System.Console.WriteLine(e.Message + e.StackTrace);
137-
Trace.TraceWarning(e.Message + e.StackTrace);
136+
Trace.WriteLine(e);
138137
}
139138
}
140139
if (MPManager.Simulator.Confirmer != null)

Source/Orts.Simulation/MultiPlayer/MPManager.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,8 @@ private void RemovePlayer()
666666
}
667667
catch (Exception e)
668668
{
669-
System.Console.WriteLine(e + e.StackTrace); return;
669+
Trace.WriteLine(e);
670+
return;
670671
}
671672
playersRemoved.Clear();
672673

@@ -838,8 +839,6 @@ public static void LocoChange(Train t, TrainCar lead)
838839

839840
public TrainCar SubCar(Train train, string wagonFilePath, int length)
840841
{
841-
Console.WriteLine("Will substitute with your existing stocks\n.");
842-
843842
try
844843
{
845844
char type = 'w';
@@ -856,7 +855,7 @@ public TrainCar SubCar(Train train, string wagonFilePath, int length)
856855
}
857856
catch (Exception error)
858857
{
859-
Console.WriteLine(error.Message + "Substitution failed, will ignore it\n.");
858+
Trace.WriteLine(new FileLoadException("Skipping non-substitutable car " + wagonFilePath, error));
860859
return null;
861860
}
862861
}

Source/Orts.Simulation/MultiPlayer/Message.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// COPYRIGHT 2012, 2013 by the Open Rails project.
1+
// COPYRIGHT 2012, 2013 by the Open Rails project.
22
//
33
// This file is part of Open Rails.
44
//
@@ -473,7 +473,7 @@ public override void HandleMsg()
473473
}
474474
else
475475
{
476-
System.Console.WriteLine("Wrong version of protocol, will play in single mode, please update to version " + MPManager.Instance().version);
476+
Trace.TraceWarning("Wrong version of protocol, will play in single mode, please update to version " + MPManager.Instance().version);
477477
throw new MultiPlayerError();//client, close the connection
478478
}
479479
}
@@ -1385,7 +1385,7 @@ public override void HandleMsg() //only client will get message, thus will set s
13851385
}
13861386
catch (Exception error)
13871387
{
1388-
Console.WriteLine(wagonFilePath + " " + error);
1388+
Trace.WriteLine(new FileLoadException(wagonFilePath, error));
13891389
car = MPManager.Instance().SubCar(train, wagonFilePath, lengths[i]);
13901390
}
13911391

@@ -1614,7 +1614,7 @@ public override void HandleMsg() //only client will get message, thus will set s
16141614
}
16151615
catch (Exception error)
16161616
{
1617-
Console.WriteLine(wagonFilePath + " " + error);
1617+
Trace.WriteLine(new FileLoadException(wagonFilePath, error));
16181618
car = MPManager.Instance().SubCar(train, wagonFilePath, lengths[i]);
16191619
}
16201620

@@ -1664,7 +1664,7 @@ public override void HandleMsg() //only client will get message, thus will set s
16641664
}
16651665
catch (Exception error)
16661666
{
1667-
Console.WriteLine(wagonFilePath + " " + error);
1667+
Trace.WriteLine(new FileLoadException(wagonFilePath, error));
16681668
car = MPManager.Instance().SubCar(train, wagonFilePath, lengths[i]);
16691669
}
16701670

Source/Orts.Simulation/MultiPlayer/OnlineTrains.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
using ORTS.Scripting.Api;
2424
using System;
2525
using System.Collections.Generic;
26+
using System.Diagnostics;
2627
using System.IO;
2728
using System.Linq;
2829

@@ -216,7 +217,7 @@ public void AddPlayers(MSGPlayer player, OnlinePlayer p)
216217
}
217218
catch (Exception error)
218219
{
219-
Console.WriteLine(error.Message);
220+
Trace.WriteLine(error);
220221
car = MPManager.Instance().SubCar(train, wagonFilePath, player.lengths[i]);
221222
}
222223

Source/RunActivity/Viewer3D/Processes/GameStateRunActivity.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// COPYRIGHT 2021 by the Open Rails project.
1+
// COPYRIGHT 2021 by the Open Rails project.
22
//
33
// This file is part of Open Rails.
44
//
@@ -1164,7 +1164,7 @@ void InitSimulator(UserSettings settings, string[] args, string mode, string act
11641164
catch (Exception error)
11651165
{
11661166
Trace.WriteLine(error);
1167-
Console.WriteLine("Connection error - will play in single mode.");
1167+
Trace.TraceWarning("Connection error - will play in single mode.");
11681168
Server = null;
11691169
}
11701170
}
@@ -1183,7 +1183,7 @@ void InitSimulator(UserSettings settings, string[] args, string mode, string act
11831183
catch (Exception error)
11841184
{
11851185
Trace.WriteLine(error);
1186-
Console.WriteLine("Connection error - will play in single mode.");
1186+
Trace.TraceWarning("Connection error - will play in single mode.");
11871187
Client = null;
11881188
}
11891189
}

Source/RunActivity/Viewer3D/Shaders.cs

+6-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
// This file is the responsibility of the 3D & Environment Team.
1919

2020
using System;
21+
using System.Diagnostics;
2122
using System.IO;
2223
using Microsoft.Xna.Framework;
2324
using Microsoft.Xna.Framework.Content.Pipeline;
@@ -57,7 +58,7 @@ class ProcessorContext : ContentProcessorContext
5758
readonly OpaqueDataDictionary parameters = new OpaqueDataDictionary();
5859

5960
public override ContentBuildLogger Logger { get { return logger; } }
60-
readonly ContentBuildLogger logger = new Logger();
61+
readonly ContentBuildLogger logger = new TraceContentBuildLogger();
6162

6263
public override void AddDependency(string filename) { }
6364
public override void AddOutputFile(string filename) { }
@@ -67,11 +68,11 @@ public override void AddOutputFile(string filename) { }
6768
public override ExternalReference<TOutput> BuildAsset<TInput, TOutput>(ExternalReference<TInput> sourceAsset, string processorName, OpaqueDataDictionary processorParameters, string importerName, string assetName) { throw new NotImplementedException(); }
6869
}
6970

70-
class Logger : ContentBuildLogger
71+
class TraceContentBuildLogger : ContentBuildLogger
7172
{
72-
public override void LogMessage(string message, params object[] messageArgs) => Console.WriteLine(message, messageArgs);
73-
public override void LogImportantMessage(string message, params object[] messageArgs) => Console.WriteLine(message, messageArgs);
74-
public override void LogWarning(string helpLink, ContentIdentity contentIdentity, string message, params object[] messageArgs) => Console.WriteLine(message, messageArgs);
73+
public override void LogMessage(string message, params object[] messageArgs) => Trace.TraceInformation(message, messageArgs);
74+
public override void LogImportantMessage(string message, params object[] messageArgs) => Trace.TraceInformation(message, messageArgs);
75+
public override void LogWarning(string helpLink, ContentIdentity contentIdentity, string message, params object[] messageArgs) => Trace.TraceWarning(message, messageArgs);
7576
}
7677

7778
[CallOnThread("Render")]

0 commit comments

Comments
 (0)