From 7fe761bacbf3c7eb3d72a753468b2be24489ddd1 Mon Sep 17 00:00:00 2001 From: Zack Piispanen Date: Mon, 16 Mar 2015 19:49:23 -0400 Subject: [PATCH] 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) --- TShockAPI/TShock.cs | 4 +++- TShockAPI/TextLog.cs | 9 ++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) 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),