Make an instance variable part of TShock so that the Loggers have access to it for using the ServerAPI logger because sometimes the log has been disposed of when we write to it (i.e. other plugins)

This commit is contained in:
Zack Piispanen 2015-03-16 19:49:23 -04:00
parent 5488be0857
commit 7fe761bacb
2 changed files with 9 additions and 4 deletions

View file

@ -77,6 +77,7 @@ namespace TShockAPI
public static StatTracker StatTracker = new StatTracker();
public static UpdateManager UpdateManager;
public static ILog Log;
public static TerrariaPlugin instance;
/// <summary>
/// Used for implementing REST Tokens prior to the REST system starting up.
/// </summary>
@ -116,6 +117,7 @@ namespace TShockAPI
ServerSideCharacterConfig.StartingInventory.Add(new NetItem { netID = -13, prefix = 0, stack = 1 });
ServerSideCharacterConfig.StartingInventory.Add(new NetItem { netID = -16, prefix = 0, stack = 1 });
Order = 0;
instance = this;
}
@ -261,7 +263,7 @@ namespace TShockAPI
ServerApi.Hooks.ProjectileSetDefaults.Register(this, OnProjectileSetDefaults);
ServerApi.Hooks.WorldStartHardMode.Register(this, OnStartHardMode);
ServerApi.Hooks.WorldSave.Register(this, SaveManager.Instance.OnSaveWorld);
ServerApi.Hooks.WorldChristmasCheck.Register(this, OnXmasCheck);
ServerApi.Hooks.WorldChristmasCheck.Register(this, OnXmasCheck);
ServerApi.Hooks.WorldHalloweenCheck.Register(this, OnHalloweenCheck);
ServerApi.Hooks.NetNameCollision.Register(this, NetHooks_NameCollision);
Hooks.PlayerHooks.PlayerPreLogin += OnPlayerPreLogin;

View file

@ -20,6 +20,7 @@ using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using TerrariaApi.Server;
namespace TShockAPI
{
@ -226,15 +227,17 @@ namespace TShockAPI
caller = meth.DeclaringType.Name;
}
try
{
_logWriter.WriteLine("{0} - {1}: {2}: {3}",
var logEntry = String.Format("{0} - {1}: {2}: {3}",
DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture),
caller, level.ToString().ToUpper(), message);
try
{
_logWriter.WriteLine(logEntry);
_logWriter.Flush();
}
catch (ObjectDisposedException)
{
ServerApi.LogWriter.PluginWriteLine(TShock.instance, logEntry, TraceLevel.Error);
Console.WriteLine("Unable to write to log as log has been disposed.");
Console.WriteLine("{0} - {1}: {2}: {3}",
DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture),