diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index bef1506a..7310011c 100755 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -77,6 +77,7 @@ namespace TShockAPI public static StatTracker StatTracker = new StatTracker(); public static UpdateManager UpdateManager; public static ILog Log; + public static TerrariaPlugin instance; /// /// Used for implementing REST Tokens prior to the REST system starting up. /// @@ -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; diff --git a/TShockAPI/TextLog.cs b/TShockAPI/TextLog.cs index 5edfeb8b..9812e168 100644 --- a/TShockAPI/TextLog.cs +++ b/TShockAPI/TextLog.cs @@ -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),