Terraria ModLoader  0.10.1.5
A framework for Terraria mods
Terraria.ModLoader.ErrorLogger Class Reference

NOTE: This class is deprecated. Use Terraria.ModLoader.Logging instead (see ExampleMod for example) This class consists of functions that write error messages to text files for you to read. It also lets you write logs to text files. More...

+ Collaboration diagram for Terraria.ModLoader.ErrorLogger:

Static Public Member Functions

static void ClearLogs ()
 NOTE: Deprecated. Deletes all log files. More...
 
static void Log (string message)
 NOTE: Deprecated. Please use your own ILog instead, see ExampleMod for an example You can use this method for your own testing purposes. The message will be added to the Logs.txt file in the Logs folder. More...
 
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 an object for your own testing purposes. The message will be added to the Logs.txt file in the Logs folder. More...
 

Static Public Attributes

static readonly string LogPath = Logging.LogDir
 NOTE: Deprecated. Use Terraria.ModLoader.Logging.LogDir instead The file path to which logs are written and stored. More...
 

Static Private Member Functions

static string GetCallerName ()
 

Static Private Attributes

static Object logExceptionLock = new Object()
 
static Object logLock = new Object()
 

Detailed Description

NOTE: This class is deprecated. Use Terraria.ModLoader.Logging instead (see ExampleMod for example) This class consists of functions that write error messages to text files for you to read. It also lets you write logs to text files.

Definition at line 14 of file ErrorLogger.cs.

Member Function Documentation

static void Terraria.ModLoader.ErrorLogger.ClearLogs ( )
static

NOTE: Deprecated. Deletes all log files.

Definition at line 97 of file ErrorLogger.cs.

References Terraria.ModLoader.Logging.LogDir.

97  {
98  lock (logLock) {
99  if (!Directory.Exists(Logging.LogDir))
100  Directory.CreateDirectory(Logging.LogDir);
101 
102  string[] files = new string[] {
103  LogPath + Path.DirectorySeparatorChar + "Logs.txt",
104  LogPath + Path.DirectorySeparatorChar + "Network Error.txt",
105  LogPath + Path.DirectorySeparatorChar + "Runtime Error.txt",
106  };
107  foreach (var file in files) {
108  try {
109  File.Delete(file);
110  }
111  catch (Exception) {
112  // Don't worry about it, modder or player might have the file open in tail or notepad.
113  }
114  }
115  }
116  }
static readonly string LogPath
NOTE: Deprecated. Use Terraria.ModLoader.Logging.LogDir instead The file path to which logs are writt...
Definition: ErrorLogger.cs:21
static string Terraria.ModLoader.ErrorLogger.GetCallerName ( )
staticprivate

Definition at line 85 of file ErrorLogger.cs.

85  {
86  StackTrace stackTrace = new StackTrace();
87  Assembly asm = stackTrace.GetFrame(2).GetMethod().DeclaringType.Assembly;
88  string name = asm.GetName().Name;
89  return name.Contains("_") ? name.Split('_')[0] : name;
90  }
static void Terraria.ModLoader.ErrorLogger.Log ( string  message)
static

NOTE: Deprecated. Please use your own ILog instead, see ExampleMod for an example You can use this method for your own testing purposes. The message will be added to the Logs.txt file in the Logs folder.

Definition at line 31 of file ErrorLogger.cs.

References Terraria.ModLoader.ModLoader.GetMod(), and Terraria.ModLoader.Mod.Logger.

31  {
32  string callerName = GetCallerName();
33  Mod callerMod = ModLoader.GetMod(callerName);
34  if (callerMod == null) {
35  Logging.tML.WarnFormat("Tried to forward ErrorLogger.Log for mod {0} but failed (mod not found!)", callerName);
36  }
37  else {
38  callerMod.Logger.Info(message);
39  }
40  }
static string GetCallerName()
Definition: ErrorLogger.cs:85

+ Here is the call graph for this function:

static void Terraria.ModLoader.ErrorLogger.Log ( object  param,
bool  alternateOutput = false 
)
static

NOTE: Deprecated. Please use your own ILog instead, see ExampleMod for an example Allows you to log an object for your own testing purposes. The message will be added to the Logs.txt file in the Logs folder.

Parameters
paramThe object to be logged.
alternateOutputIf true, the object's data will be manually retrieved and logged. If false, the object's ToString method is logged.

Definition at line 49 of file ErrorLogger.cs.

References Terraria.ModLoader.ModLoader.GetMod(), and Terraria.ModLoader.Mod.Logger.

49  {
50  string getParamString() {
51  StringBuilder sb = new StringBuilder();
52  sb.AppendLine("Object type: " + param.GetType());
53  foreach (PropertyInfo property in param.GetType().GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) {
54  sb.AppendLine("PROPERTY " + property.Name + " = " + property.GetValue(param, null) + "\n");
55  }
56 
57  foreach (FieldInfo field in param.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) {
58  sb.AppendLine("FIELD " + field.Name + " = " + (field.GetValue(param).ToString() != "" ? field.GetValue(param) : "(Field value not found)") + "\n");
59  }
60 
61  foreach (MethodInfo method in param.GetType().GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) {
62  sb.AppendLine("METHOD " + method.Name + "\n");
63  }
64 
65  int temp = 0;
66 
67  foreach (ConstructorInfo constructor in param.GetType().GetConstructors(BindingFlags.Public | BindingFlags.NonPublic)) {
68  temp++;
69  sb.AppendLine("CONSTRUCTOR " + temp + " : " + constructor.Name + "\n");
70  }
71 
72  return sb.ToString();
73  }
74 
75  string callerName = GetCallerName();
76  Mod callerMod = ModLoader.GetMod(callerName);
77  if (callerMod == null) {
78  Logging.tML.WarnFormat("Tried to forward ErrorLogger.Log for mod {0} but failed (mod not found!)", callerName);
79  }
80  else {
81  callerMod.Logger.Info(!alternateOutput ? param.ToString() : getParamString());
82  }
83  }
static string GetCallerName()
Definition: ErrorLogger.cs:85

+ Here is the call graph for this function:

Member Data Documentation

Object Terraria.ModLoader.ErrorLogger.logExceptionLock = new Object()
staticprivate

Definition at line 23 of file ErrorLogger.cs.

Object Terraria.ModLoader.ErrorLogger.logLock = new Object()
staticprivate

Definition at line 25 of file ErrorLogger.cs.

readonly string Terraria.ModLoader.ErrorLogger.LogPath = Logging.LogDir
static

NOTE: Deprecated. Use Terraria.ModLoader.Logging.LogDir instead The file path to which logs are written and stored.

Definition at line 21 of file ErrorLogger.cs.