Inventory logger
This commit is contained in:
parent
29fba4b7cb
commit
de2057789a
41 changed files with 12834 additions and 171 deletions
139
Shared/Debug.cs
Normal file
139
Shared/Debug.cs
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
using System;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
|
||||
using Decal.Adapter;
|
||||
|
||||
namespace Mag.Shared
|
||||
{
|
||||
static class Debug
|
||||
{
|
||||
static string _debugLogPath;
|
||||
static string _errorLogPath;
|
||||
|
||||
static string _pluginName;
|
||||
|
||||
public static void Init(string debugLogPath, string errorLogPath, string pluginName)
|
||||
{
|
||||
_debugLogPath = debugLogPath;
|
||||
_errorLogPath = errorLogPath;
|
||||
|
||||
_pluginName = pluginName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This will write to the debug.txt
|
||||
/// </summary>
|
||||
public static void LogDebug(string message)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (String.IsNullOrEmpty(_debugLogPath))
|
||||
return;
|
||||
|
||||
FileInfo fileInfo = new FileInfo(_debugLogPath);
|
||||
|
||||
// Limit the file to 1MB
|
||||
bool append = !(fileInfo.Exists && fileInfo.Length > 1048576);
|
||||
|
||||
using (StreamWriter writer = new StreamWriter(fileInfo.FullName, append))
|
||||
{
|
||||
writer.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "," + message);
|
||||
writer.Close();
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Eat the exception, yumm.
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This will only write the exception to the errors.txt file if DebugEnabled is true.
|
||||
/// </summary>
|
||||
public static void LogException(Exception ex, string note = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
//if (!Settings.SettingsManager.Misc.DebuggingEnabled.Value)
|
||||
// return;
|
||||
|
||||
if (note != null)
|
||||
MyClasses.VCS_Connector.SendChatTextCategorized("Errors", "<{" + _pluginName + "}>: " + "Exception caught: " + ex.Message + Environment.NewLine + ex.Source + Environment.NewLine + ex.StackTrace + Environment.NewLine + "Note: " + note, 5);
|
||||
else
|
||||
MyClasses.VCS_Connector.SendChatTextCategorized("Errors", "<{" + _pluginName + "}>: " + "Exception caught: " + ex.Message + Environment.NewLine + ex.Source + Environment.NewLine + ex.StackTrace, 5);
|
||||
|
||||
if (String.IsNullOrEmpty(_errorLogPath))
|
||||
return;
|
||||
|
||||
FileInfo fileInfo = new FileInfo(_errorLogPath);
|
||||
|
||||
// Limit the file to 1MB
|
||||
bool append = !(fileInfo.Exists && fileInfo.Length > 1048576);
|
||||
|
||||
using (StreamWriter writer = new StreamWriter(fileInfo.FullName, append))
|
||||
{
|
||||
writer.WriteLine("============================================================================");
|
||||
|
||||
writer.WriteLine(DateTime.Now.ToString(CultureInfo.InvariantCulture));
|
||||
writer.WriteLine(ex);
|
||||
|
||||
if (note != null)
|
||||
writer.WriteLine("Note: " + note);
|
||||
|
||||
writer.WriteLine("============================================================================");
|
||||
writer.WriteLine("");
|
||||
writer.Close();
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Eat the exception, yumm.
|
||||
}
|
||||
}
|
||||
|
||||
public static void LogText(string text)
|
||||
{
|
||||
try
|
||||
{
|
||||
//if (!Settings.SettingsManager.Misc.DebuggingEnabled.Value)
|
||||
// return;
|
||||
|
||||
MyClasses.VCS_Connector.SendChatTextCategorized("CommandLine", "<{" + _pluginName + "}>: " + "Log Text: " + text, 5);
|
||||
|
||||
if (String.IsNullOrEmpty(_errorLogPath))
|
||||
return;
|
||||
|
||||
FileInfo fileInfo = new FileInfo(_errorLogPath);
|
||||
|
||||
// Limit the file to 1MB
|
||||
bool append = !(fileInfo.Exists && fileInfo.Length > 1048576);
|
||||
|
||||
using (StreamWriter writer = new StreamWriter(fileInfo.FullName, append))
|
||||
{
|
||||
writer.WriteLine(DateTime.Now + ": " + text);
|
||||
writer.Close();
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { LogException(ex); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This will only write the message to the chat if DebugEnabled is true.
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
/// <param name="color"></param>
|
||||
/// <param name="target"></param>
|
||||
public static void WriteToChat(string message, int color = 5, int target = 1)
|
||||
{
|
||||
try
|
||||
{
|
||||
//if (!Settings.SettingsManager.Misc.DebuggingEnabled.Value)
|
||||
// return;
|
||||
|
||||
MyClasses.VCS_Connector.SendChatTextCategorized("CommandLine", "<{" + _pluginName + "}>: " + message, color, target);
|
||||
}
|
||||
catch (Exception ex) { LogException(ex); }
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue