Skip to content

Commit

Permalink
fix: Log messages using Trace instead of Console
Browse files Browse the repository at this point in the history
  • Loading branch information
twpol committed Dec 23, 2024
1 parent abe5bee commit 5a94c4e
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Source/Orts.Formats.Msts/TrackSectionsFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Source/Orts.Parsers.Msts/SBR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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@@"))
Expand Down
3 changes: 1 addition & 2 deletions Source/Orts.Simulation/MultiPlayer/ClientComm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions Source/Orts.Simulation/MultiPlayer/MPManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,8 @@ private void RemovePlayer()
}
catch (Exception e)
{
System.Console.WriteLine(e + e.StackTrace); return;
Trace.WriteLine(e);
return;
}
playersRemoved.Clear();

Expand Down Expand Up @@ -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';
Expand All @@ -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;
}
}
Expand Down
10 changes: 5 additions & 5 deletions Source/Orts.Simulation/MultiPlayer/Message.cs
Original file line number Diff line number Diff line change
@@ -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.
//
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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]);
}

Expand Down Expand Up @@ -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]);
}

Expand Down Expand Up @@ -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]);
}

Expand Down
3 changes: 2 additions & 1 deletion Source/Orts.Simulation/MultiPlayer/OnlineTrains.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using ORTS.Scripting.Api;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

Expand Down Expand Up @@ -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]);
}

Expand Down
6 changes: 3 additions & 3 deletions Source/RunActivity/Viewer3D/Processes/GameStateRunActivity.cs
Original file line number Diff line number Diff line change
@@ -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.
//
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
}
}
Expand Down
11 changes: 6 additions & 5 deletions Source/RunActivity/Viewer3D/Shaders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) { }
Expand All @@ -67,11 +68,11 @@ public override void AddOutputFile(string filename) { }
public override ExternalReference<TOutput> BuildAsset<TInput, TOutput>(ExternalReference<TInput> 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")]
Expand Down

0 comments on commit 5a94c4e

Please sign in to comment.