diff --git a/Source/Orts.Formats.Msts/TrackSectionsFile.cs b/Source/Orts.Formats.Msts/TrackSectionsFile.cs index fefb78a10..5d19ce64c 100644 --- a/Source/Orts.Formats.Msts/TrackSectionsFile.cs +++ b/Source/Orts.Formats.Msts/TrackSectionsFile.cs @@ -344,7 +344,7 @@ private void AddPath(STFReader stf, TrackPath path) } catch (Exception e) { - System.Console.WriteLine("Warning: in route tsection.dat " + e.Message); + Trace.WriteLine(new FileLoadException("In route tsection.dat", e)); } } public uint NoSections; diff --git a/Source/Orts.Parsers.Msts/SBR.cs b/Source/Orts.Parsers.Msts/SBR.cs index 7fab3aa00..d026bf6e6 100644 --- a/Source/Orts.Parsers.Msts/SBR.cs +++ b/Source/Orts.Parsers.Msts/SBR.cs @@ -65,7 +65,7 @@ public static SBR Open(string filename) else if (headerString.StartsWith("\r\nSIMISA")) { // ie us1rd2l1000r10d.s, we are going to allow this but warn - Console.Error.WriteLine("Improper header in " + filename); + Trace.TraceWarning("Improper header in " + filename); fb.Read(buffer, 0, 4); } else if (!headerString.StartsWith("SIMISA@@")) diff --git a/Source/Orts.Simulation/MultiPlayer/ClientComm.cs b/Source/Orts.Simulation/MultiPlayer/ClientComm.cs index da94d96a6..0a5d1907b 100644 --- a/Source/Orts.Simulation/MultiPlayer/ClientComm.cs +++ b/Source/Orts.Simulation/MultiPlayer/ClientComm.cs @@ -133,8 +133,7 @@ public void Receive(object client) } catch (Exception e) { - System.Console.WriteLine(e.Message + e.StackTrace); - Trace.TraceWarning(e.Message + e.StackTrace); + Trace.WriteLine(e); } } if (MPManager.Simulator.Confirmer != null) diff --git a/Source/Orts.Simulation/MultiPlayer/MPManager.cs b/Source/Orts.Simulation/MultiPlayer/MPManager.cs index b3fa6d701..20a0a7ea5 100644 --- a/Source/Orts.Simulation/MultiPlayer/MPManager.cs +++ b/Source/Orts.Simulation/MultiPlayer/MPManager.cs @@ -666,7 +666,8 @@ private void RemovePlayer() } catch (Exception e) { - System.Console.WriteLine(e + e.StackTrace); return; + Trace.WriteLine(e); + return; } playersRemoved.Clear(); @@ -838,8 +839,6 @@ public static void LocoChange(Train t, TrainCar lead) public TrainCar SubCar(Train train, string wagonFilePath, int length) { - Console.WriteLine("Will substitute with your existing stocks\n."); - try { char type = 'w'; @@ -856,7 +855,7 @@ public TrainCar SubCar(Train train, string wagonFilePath, int length) } catch (Exception error) { - Console.WriteLine(error.Message + "Substitution failed, will ignore it\n."); + Trace.WriteLine(new FileLoadException("Skipping non-substitutable car " + wagonFilePath, error)); return null; } } diff --git a/Source/Orts.Simulation/MultiPlayer/Message.cs b/Source/Orts.Simulation/MultiPlayer/Message.cs index 2ba792a41..57e2ee331 100644 --- a/Source/Orts.Simulation/MultiPlayer/Message.cs +++ b/Source/Orts.Simulation/MultiPlayer/Message.cs @@ -1,4 +1,4 @@ -// COPYRIGHT 2012, 2013 by the Open Rails project. +// COPYRIGHT 2012, 2013 by the Open Rails project. // // This file is part of Open Rails. // @@ -473,7 +473,7 @@ public override void HandleMsg() } else { - System.Console.WriteLine("Wrong version of protocol, will play in single mode, please update to version " + MPManager.Instance().version); + Trace.TraceWarning("Wrong version of protocol, will play in single mode, please update to version " + MPManager.Instance().version); throw new MultiPlayerError();//client, close the connection } } @@ -1385,7 +1385,7 @@ public override void HandleMsg() //only client will get message, thus will set s } catch (Exception error) { - Console.WriteLine(wagonFilePath + " " + error); + Trace.WriteLine(new FileLoadException(wagonFilePath, error)); car = MPManager.Instance().SubCar(train, wagonFilePath, lengths[i]); } @@ -1614,7 +1614,7 @@ public override void HandleMsg() //only client will get message, thus will set s } catch (Exception error) { - Console.WriteLine(wagonFilePath + " " + error); + Trace.WriteLine(new FileLoadException(wagonFilePath, error)); car = MPManager.Instance().SubCar(train, wagonFilePath, lengths[i]); } @@ -1664,7 +1664,7 @@ public override void HandleMsg() //only client will get message, thus will set s } catch (Exception error) { - Console.WriteLine(wagonFilePath + " " + error); + Trace.WriteLine(new FileLoadException(wagonFilePath, error)); car = MPManager.Instance().SubCar(train, wagonFilePath, lengths[i]); } diff --git a/Source/Orts.Simulation/MultiPlayer/OnlineTrains.cs b/Source/Orts.Simulation/MultiPlayer/OnlineTrains.cs index 7cb7d3bd8..a4eb3e152 100644 --- a/Source/Orts.Simulation/MultiPlayer/OnlineTrains.cs +++ b/Source/Orts.Simulation/MultiPlayer/OnlineTrains.cs @@ -23,6 +23,7 @@ using ORTS.Scripting.Api; using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; @@ -216,7 +217,7 @@ public void AddPlayers(MSGPlayer player, OnlinePlayer p) } catch (Exception error) { - Console.WriteLine(error.Message); + Trace.WriteLine(error); car = MPManager.Instance().SubCar(train, wagonFilePath, player.lengths[i]); } diff --git a/Source/RunActivity/Viewer3D/Processes/GameStateRunActivity.cs b/Source/RunActivity/Viewer3D/Processes/GameStateRunActivity.cs index 019f2da4d..1b47409e4 100644 --- a/Source/RunActivity/Viewer3D/Processes/GameStateRunActivity.cs +++ b/Source/RunActivity/Viewer3D/Processes/GameStateRunActivity.cs @@ -1,4 +1,4 @@ -// COPYRIGHT 2021 by the Open Rails project. +// COPYRIGHT 2021 by the Open Rails project. // // This file is part of Open Rails. // @@ -1164,7 +1164,7 @@ void InitSimulator(UserSettings settings, string[] args, string mode, string act catch (Exception error) { Trace.WriteLine(error); - Console.WriteLine("Connection error - will play in single mode."); + Trace.TraceWarning("Connection error - will play in single mode."); Server = null; } } @@ -1183,7 +1183,7 @@ void InitSimulator(UserSettings settings, string[] args, string mode, string act catch (Exception error) { Trace.WriteLine(error); - Console.WriteLine("Connection error - will play in single mode."); + Trace.TraceWarning("Connection error - will play in single mode."); Client = null; } } diff --git a/Source/RunActivity/Viewer3D/Shaders.cs b/Source/RunActivity/Viewer3D/Shaders.cs index 19cbfb736..abe715d36 100644 --- a/Source/RunActivity/Viewer3D/Shaders.cs +++ b/Source/RunActivity/Viewer3D/Shaders.cs @@ -18,6 +18,7 @@ // This file is the responsibility of the 3D & Environment Team. using System; +using System.Diagnostics; using System.IO; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content.Pipeline; @@ -57,7 +58,7 @@ class ProcessorContext : ContentProcessorContext readonly OpaqueDataDictionary parameters = new OpaqueDataDictionary(); public override ContentBuildLogger Logger { get { return logger; } } - readonly ContentBuildLogger logger = new Logger(); + readonly ContentBuildLogger logger = new TraceContentBuildLogger(); public override void AddDependency(string filename) { } public override void AddOutputFile(string filename) { } @@ -67,11 +68,11 @@ public override void AddOutputFile(string filename) { } public override ExternalReference BuildAsset(ExternalReference sourceAsset, string processorName, OpaqueDataDictionary processorParameters, string importerName, string assetName) { throw new NotImplementedException(); } } - class Logger : ContentBuildLogger + class TraceContentBuildLogger : ContentBuildLogger { - public override void LogMessage(string message, params object[] messageArgs) => Console.WriteLine(message, messageArgs); - public override void LogImportantMessage(string message, params object[] messageArgs) => Console.WriteLine(message, messageArgs); - public override void LogWarning(string helpLink, ContentIdentity contentIdentity, string message, params object[] messageArgs) => Console.WriteLine(message, messageArgs); + public override void LogMessage(string message, params object[] messageArgs) => Trace.TraceInformation(message, messageArgs); + public override void LogImportantMessage(string message, params object[] messageArgs) => Trace.TraceInformation(message, messageArgs); + public override void LogWarning(string helpLink, ContentIdentity contentIdentity, string message, params object[] messageArgs) => Trace.TraceWarning(message, messageArgs); } [CallOnThread("Render")]