Terraria ModLoader  0.11.7.8
A mod to make and play Terraria mods
ErrorLogger.cs
Go to the documentation of this file.
1 using System;
2 using System.Diagnostics;
3 using System.IO;
4 using System.Reflection;
5 using System.Text;
6 using Terraria.ModLoader.Core;
7 
8 namespace Terraria.ModLoader
9 {
14  [Obsolete("This class is deprecated. Use Terraria.ModLoader.Logging instead (see ExampleMod for example)", false)]
15  public static class ErrorLogger
16  {
21  [Obsolete("Please use Terraria.ModLoader.Logging.LogDir instead", false)]
22  public static readonly string LogPath = Logging.LogDir;
23 
24  private static Object logLock = new Object();
29  [Obsolete("Please use your own ILog instead, see ExampleMod for an example", false)]
30  public static void Log(string message)
31  {
32  if (AssemblyManager.FirstModInStackTrace(new StackTrace(), out string modName) && ModLoader.GetMod(modName) is Mod mod) {
33  mod.Logger.Info(message);
34  }
35  else {
36  Logging.tML.WarnFormat("Tried to forward ErrorLogger.Log for mod {0} but failed (mod not found!)", modName);
37  }
38  }
39 
46  [Obsolete("Please use your own ILog instead, see ExampleMod for an example", false)]
47  public static void Log(object param, bool alternateOutput = false) {
48  string getParamString() {
49  StringBuilder sb = new StringBuilder();
50  sb.AppendLine("Object type: " + param.GetType());
51  foreach (PropertyInfo property in param.GetType().GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) {
52  sb.AppendLine("PROPERTY " + property.Name + " = " + property.GetValue(param, null) + "\n");
53  }
54 
55  foreach (FieldInfo field in param.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) {
56  sb.AppendLine("FIELD " + field.Name + " = " + (field.GetValue(param).ToString() != "" ? field.GetValue(param) : "(Field value not found)") + "\n");
57  }
58 
59  foreach (MethodInfo method in param.GetType().GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) {
60  sb.AppendLine("METHOD " + method.Name + "\n");
61  }
62 
63  int temp = 0;
64 
65  foreach (ConstructorInfo constructor in param.GetType().GetConstructors(BindingFlags.Public | BindingFlags.NonPublic)) {
66  temp++;
67  sb.AppendLine("CONSTRUCTOR " + temp + " : " + constructor.Name + "\n");
68  }
69 
70  return sb.ToString();
71  }
72 
73  Log(!alternateOutput ? param.ToString() : getParamString());
74  }
75 
80  [Obsolete("Please use Terraria.ModLoader.Logging instead", false)]
81  public static void ClearLogs() {
82  lock (logLock) {
83  if (!Directory.Exists(Logging.LogDir))
84  Directory.CreateDirectory(Logging.LogDir);
85 
86  string[] files = new string[] {
87  LogPath + Path.DirectorySeparatorChar + "Logs.txt",
88  LogPath + Path.DirectorySeparatorChar + "Network Error.txt",
89  LogPath + Path.DirectorySeparatorChar + "Runtime Error.txt",
90  };
91  foreach (var file in files) {
92  try {
93  File.Delete(file);
94  }
95  catch (Exception) {
96  // Don't worry about it, modder or player might have the file open in tail or notepad.
97  }
98  }
99  }
100  }
101  }
102 }
static void Log(string message)
NOTE: Deprecated. Please use your own ILog instead, see ExampleMod for an example You can use this me...
Definition: ErrorLogger.cs:30
This serves as the central class which loads mods. It contains many static fields and methods related...
Definition: ModLoader.cs:28
static void Log(object param, bool alternateOutput=false)
NOTE: Deprecated. Please use your own ILog instead, see ExampleMod for an example Allows you to log a...
Definition: ErrorLogger.cs:47
NOTE: This class is deprecated. Use Logging instead (see ExampleMod for example) This class consists ...
Definition: ErrorLogger.cs:15
static readonly string LogDir
Definition: Logging.cs:25
Mod is an abstract class that you will override. It serves as a central place from which the mod's co...
Definition: Mod.cs:24
static Mod GetMod(string name)
Gets the instance of the Mod with the specified name.
Definition: ModLoader.cs:90
static void ClearLogs()
NOTE: Deprecated. Deletes all log files.
Definition: ErrorLogger.cs:81