public void ReplaceLog(ILog oldLog, ILogNode newNode) { lock (this.logs) { ILogNode oldNode = null; // Find the ILogNode for the old log. foreach (ILogNode logNode in this.logs) { if (ReferenceEquals(logNode.Log, oldLog)) { oldNode = logNode; break; } } if (oldNode != null) { // Change all nodes matching the old ILogNode to use the new node. for (LinkedListNode <ILogNode> node = this.logs.First; node != null; node = node.Next) { if (node.Value.Equals(oldNode)) { node.Value = newNode; } } } this.BakeImpl(); } }
public void LogExceptionFile(Exception ex) { string local = GameManager.GetAppDataPath(); DateTime now = DateTime.Now; string file = string.Format("{0}{1}{2}_{3}{4}{5}", now.Day.ToString("00"), now.Month.ToString("00"), now.Year.ToString("0000"), now.Hour.ToString("00"), now.Minute.ToString("00"), now.Second.ToString("00")) + ".log"; string path = Path.Combine(local, file); using (Stream stream = File.OpenWrite(path)) { using (StreamWriter writer = new StreamWriter(stream)) { writer.WriteLine("[Header]"); writer.WriteLine(now.ToLongDateString()); writer.WriteLine(now.ToLongTimeString()); writer.WriteLine("Nucleus Coop Alpha v" + Globals.Version); writer.WriteLine("[PC Specs]"); writer.WriteLine("[Message]"); writer.WriteLine(ex.Message); writer.WriteLine("[Stacktrace]"); writer.WriteLine(ex.StackTrace); for (int i = 0; i < logCallbacks.Count; i++) { ILogNode node = logCallbacks[i]; try { node.OnFailureLog(writer); } catch { writer.WriteLine("LogNode failed to log: " + node.ToString()); } } } } MessageBox.Show("Application crash. Log generated at Data/" + file); Application.Exit(); }
public void AddLog(ILogNode log) { lock (this.logs) { this.logs.AddLast(log); this.BakeImpl(); } }
public override bool Equals(ILogNode other) { // ARSE. Replacing a root should only be possible with another root. // As usual, inheritance was the wrong way to go. // Replacing a normal with a normal, fine. // Replacing a root with a normal, no - reject. // Replacing a normal with a root, hmmmm, for now let's say nope. bool equal = !(other is LogNodeNameHierarchyRoot); if (equal) { equal = base.Equals(other); } return(equal); }
public override bool IsParent(ILogNode potentialChild) { bool isParent = false; if (!ReferenceEquals(this, potentialChild)) // If not same object { string childName = potentialChild.Name; if (!string.IsNullOrEmpty(childName)) // If child has a name { isParent = this.CheckForChild(childName); } // Ends if child has a name } // Ends if not same object return(isParent); }
public override bool Equals(ILogNode other) { // ARSE. Replacing a root should only be possible with another root. // As usual, inheritance was the wrong way to go. // Replacing a normal with a normal, fine. // Replacing a root with a normal, no - reject. // Replacing a normal with a root, hmmmm, for now let's say nope. // i.e. normals and root's don't interact. // Sadly, this is going to be busted working the other way around without implementing Equals in both classes. C'est la vie. bool equal = other is LogNodeNameHierarchyRoot; if (equal) { equal = Equals(this, other); } return(equal); }
/** * Takes the "next" LogNode as a parameter, to simplify chaining. */ public MessageOnlyLogFilter(ILogNode next) { NextNode = next; }
public void LogExceptionFile(Exception ex) { Log("ERROR - " + ex.Message + " | Stacktrace: " + ex.StackTrace); string local = GetAppDataPath(); DateTime now = DateTime.Now; string file = string.Format("{0}{1}{2}_{3}{4}{5}", now.Day.ToString("00"), now.Month.ToString("00"), now.Year.ToString("0000"), now.Hour.ToString("00"), now.Minute.ToString("00"), now.Second.ToString("00")) + ".log"; MessageBox.Show($"Nucleus has crashed unexpectedly. An attempt to clean up will be made.\n\n[Type]\n{ex.GetType().Name}\n\n[Message]\n{ex.Message}\n\n[Stacktrace]\n{ex.StackTrace}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Log("Attempting shut-down procedures in order to clean-up"); string[] regFiles = Directory.GetFiles(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "utils\\backup"), "*.reg", SearchOption.AllDirectories); if (regFiles.Length > 0) { LogManager.Log("Restoring backed up registry files - method 2"); foreach (string regFilePath in regFiles) { System.Diagnostics.Process proc = new System.Diagnostics.Process(); try { proc.StartInfo.FileName = "reg.exe"; proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; proc.StartInfo.CreateNoWindow = true; proc.StartInfo.UseShellExecute = false; string command = "import \"" + regFilePath + "\""; proc.StartInfo.Arguments = command; proc.Start(); proc.WaitForExit(); LogManager.Log($"Imported {Path.GetFileName(regFilePath)}"); } catch (Exception) { proc.Dispose(); } File.Delete(regFilePath); } } GenericGameHandler.Instance.End(false); while (!GenericGameHandler.Instance.HasEnded) { Thread.Sleep(1000); } Thread.Sleep(1000); string path = Path.Combine(local, file); using (Stream stream = File.OpenWrite(path)) { using (StreamWriter writer = new StreamWriter(stream)) { writer.WriteLine("[Header]"); writer.WriteLine(now.ToLongDateString()); writer.WriteLine(now.ToLongTimeString()); writer.WriteLine("Nucleus Coop Alpha v" + Globals.Version); writer.WriteLine("[Message]"); writer.WriteLine(ex.Message); writer.WriteLine("[Stacktrace]"); writer.WriteLine(ex.StackTrace); for (int i = 0; i < logCallbacks.Count; i++) { ILogNode node = logCallbacks[i]; try { node.Log(writer); } catch { writer.WriteLine("LogNode failed to log: " + node.ToString()); } } } } Windows.User32Util.ShowTaskBar(); Log("High-level error log generated at content/" + file); Application.Exit(); }
/** * Takes the "next" LogNode as a parameter, to simplify chaining. */ public MessageOnlyLogFilter(ILogNode next) { mNext = next; }
/** * Takes the "next" LogNode as a parameter, to simplify chaining. */ public MessageOnlyLogFilter (ILogNode next) { mNext = next; }
public static void SetLogNode(ILogNode node) { mLogNode = node; }
protected LogTraceSource(ILogNode logNode, IEnumerable <System.Diagnostics.TraceSource> tracesources) : base(logNode) { this.tracesources = tracesources; }
protected LogTraceSource(ILogNode logNode, params System.Diagnostics.TraceSource[] tracesources) : base(logNode) { this.tracesources = tracesources; }
internal static ILog GetLog(ILogNode logNode) { return(logNode.Log); }
// It's up to the sub-classes to call Construct with thes constructors... protected LogBase(ILogNode logNode) { this.logNode = logNode; }
public void SetNext(ILogNode node) { mNext = node; }
public static void RegisterForLogCallback(ILogNode node) { Instance.logCallbacks.Add(node); }
abstract public bool IsParent(ILogNode potentialChild);
private bool NodeIsParent(ILogNode logNode) { return(logNode.IsParent(this)); }
public override bool IsParent(ILogNode potentialChild) { return(false); }
public virtual bool Equals(ILogNode other) { return(Equals(this, other)); }
protected internal static bool Equals(ILogNode self, ILogNode other) { return(self.Name.Equals(other.Name)); }
protected static void Construct(LogBase log, ILogNode logNode) { log.logNode = logNode; logNode.Construct(); }
public static void UnregisterForLogCallback(ILogNode node) { Instance.logCallbacks.Remove(node); }
protected static void Replace(ILog logOld, LogBase log, ILogNode logNode) { log.logNode = logNode; logNode.Replace(logOld); }