private void Diagnostics_OutputDebugStackTrace(Diagnostics.LogMessage message) { StackFrame[] frames = message.StackTrace.GetFrames(); int i; for (i = 0; i < frames.Length; i++) { if (frames[i] == message.StackFrame) { Diagnostics.LogFormat diagnosticsLogFormat = this.DiagnosticsLogFormat; if (diagnosticsLogFormat == Diagnostics.LogFormat.Text) { this.outputDepugFileStreamWriter.WriteLine(); } break; } } StringBuilder stringBuilder = new StringBuilder(); while (i < frames.Length) { stringBuilder.Length = 0; StackFrame stackFrame = frames[i]; stringBuilder.AppendFormat("{0}:{1}(", stackFrame.GetMethod().ReflectedType.ToString(), stackFrame.GetMethod().Name); ParameterInfo[] parameters = stackFrame.GetMethod().GetParameters(); if (parameters.Length > 0) { for (int j = 0; j < parameters.Length; j++) { if (j > 0) { stringBuilder.Append(", "); } stringBuilder.Append(parameters[j].GetType().ToString()); } } stringBuilder.Append(")"); if (!string.IsNullOrEmpty(stackFrame.GetFileName())) { stringBuilder.AppendFormat(" at {0}({1})", stackFrame.GetFileName(), stackFrame.GetFileLineNumber()); } Diagnostics.LogFormat diagnosticsLogFormat = this.DiagnosticsLogFormat; if (diagnosticsLogFormat != Diagnostics.LogFormat.Html) { if (diagnosticsLogFormat == Diagnostics.LogFormat.Text) { this.outputDepugFileStreamWriter.WriteLine(" - {0}", stringBuilder.ToString()); } } else { this.outputDepugFileStreamWriter.WriteLine(stringBuilder.ToString()); } i++; } }
private void Diagnostics_MessageLogged(Diagnostics.LogMessage message) { if (this.outputDepugFileStreamWriter == null) { return; } Diagnostics.LogFormat diagnosticsLogFormat = this.DiagnosticsLogFormat; if (diagnosticsLogFormat != Diagnostics.LogFormat.Html) { if (diagnosticsLogFormat == Diagnostics.LogFormat.Text) { Diagnostics.LogType logType = (Diagnostics.LogType)((long)message.Flags & (long)((ulong)-16777216)); Diagnostics.LogType logType2 = logType; if (logType2 != Diagnostics.LogType.Message) { if (logType2 == Diagnostics.LogType.Warning) { this.outputDepugFileStreamWriter.Write("[W] "); goto IL_140; } if (logType2 == Diagnostics.LogType.Error) { this.outputDepugFileStreamWriter.Write("[E] "); goto IL_140; } } this.outputDepugFileStreamWriter.Write(" "); IL_140: this.outputDepugFileStreamWriter.Write(DateTime.Now.ToString("HH:mm:ss:fff")); this.outputDepugFileStreamWriter.Write(" "); this.outputDepugFileStreamWriter.WriteLine(message.Message); this.Diagnostics_OutputDebugStackTrace(message); this.outputDepugFileStreamWriter.WriteLine(); } } else { Diagnostics.LogType logType3 = (Diagnostics.LogType)((long)message.Flags & (long)((ulong)-16777216)); this.outputDepugFileStreamWriter.WriteLine("<p class=\"{1}\"><span class=\"time\">{2}</span><a onclick=\"hide('trace{0}')\">STACK</a>{3}</p>", new object[] { this.DiagnosticsLogCounter, logType3.ToString(), DateTime.Now.ToString("HH:mm:ss:fff"), message.Message }); this.outputDepugFileStreamWriter.WriteLine("<pre id=\"trace{0}\">", this.DiagnosticsLogCounter); this.Diagnostics_OutputDebugStackTrace(message); this.DiagnosticsLogCounter++; this.outputDepugFileStreamWriter.WriteLine("</pre>"); } this.outputDepugFileStreamWriter.Flush(); }
private IEnumerator SetupDiagnosticsLogFile() { string outputDebugPath = Application.OutputDebugFileName; string outputDebugFileExtension = Path.GetExtension(outputDebugPath); string outputDebugFileName = Path.GetFileNameWithoutExtension(outputDebugPath); string outputDebugDirectory = Path.GetDirectoryName(outputDebugPath); this.FormatDiagnosticsFileName(ref outputDebugFileName); outputDebugPath = Path.Combine(outputDebugDirectory, outputDebugFileName); outputDebugPath = Path.ChangeExtension(outputDebugPath, outputDebugFileExtension); try { Diagnostics.LogFormat diagnosticsLogFormat = this.DiagnosticsLogFormat; if (diagnosticsLogFormat != Diagnostics.LogFormat.Html) { if (diagnosticsLogFormat == Diagnostics.LogFormat.Text) { this.outputDepugFileStreamWriter = File.CreateText(outputDebugPath); } } else { outputDebugPath = Path.ChangeExtension(outputDebugPath, ".html"); this.outputDepugFileStreamWriter = File.CreateText(outputDebugPath); this.outputDepugFileStreamWriter.WriteLine("<script language=\"javascript\" src=\"Diagnostics.js\">"); this.outputDepugFileStreamWriter.WriteLine("</script>"); this.outputDepugFileStreamWriter.WriteLine("<link rel=\"stylesheet\" type=\"text/css\" href=\"Diagnostics.css\" />"); this.outputDepugFileStreamWriter.WriteLine("<div class=\"Header\">"); this.outputDepugFileStreamWriter.WriteLine(" <input type=\"button\" value=\"Message\" class=\"Message Button\" onclick=\"hide_class('Message')\" />"); this.outputDepugFileStreamWriter.WriteLine(" <input type=\"button\" value=\"Warning\" class=\"Warning Button\" onclick=\"hide_class('Warning')\" />"); this.outputDepugFileStreamWriter.WriteLine(" <input type=\"button\" value=\"Error\" class=\"Error Button\" onclick=\"hide_class('Error')\" />"); this.outputDepugFileStreamWriter.WriteLine(" <input type=\"button\" value=\"Assert\" class=\"Assert Button\" onclick=\"hide_class('Assert')\" />"); this.outputDepugFileStreamWriter.WriteLine("<br />"); this.outputDepugFileStreamWriter.WriteLine("</div>"); this.outputDepugFileStreamWriter.WriteLine("<h1>{0}<br />{1} {2}</h1>", DateTime.Now.ToString("f"), Application.Name.ToUpper(), Application.Version.ToString()); this.outputDepugFileStreamWriter.WriteLine("<p>Click on buttons to toggle visability. Click on STACK buttons to toggle visibility of stack traces.</p>"); } Diagnostics.AssertionFailed += this.Diagnostics_AssertionFailed; Diagnostics.MessageLogged += this.Diagnostics_MessageLogged; } catch { throw; } yield break; }
protected virtual IEnumerator OnApplicationIgnitionStarted() { Application.maximumNumberOfDiagnosticsFiles = Application.Registry.GetValue <int>(Application.Registers.MaximumNumberOfDiagnosticsFiles, 10); if (Application.maximumNumberOfDiagnosticsFiles < 1) { Application.maximumNumberOfDiagnosticsFiles = 1; } string outputDebugFileName = Application.OutputDebugFileName; string outputDebugFileExtension = Path.GetExtension(Application.OutputDebugFileName); string outputDebugFileNameWithoutExtension = Path.GetFileNameWithoutExtension(outputDebugFileName); string outputDirectory = Path.GetDirectoryName(outputDebugFileName); Diagnostics.LogFormat diagnosticsLogFormat = this.DiagnosticsLogFormat; if (diagnosticsLogFormat == Diagnostics.LogFormat.Html) { outputDebugFileExtension = ".html"; } if (Directory.Exists(outputDirectory)) { string searchPattern = outputDebugFileNameWithoutExtension + "*.*"; searchPattern = Path.ChangeExtension(searchPattern, outputDebugFileExtension); string[] files = Directory.GetFiles(outputDirectory, searchPattern); if (files.Length > Application.maximumNumberOfDiagnosticsFiles) { files = (from fileName in files orderby fileName select fileName).ToArray <string>(); for (int fileIndex = 0; fileIndex < files.Length - Application.maximumNumberOfDiagnosticsFiles; fileIndex++) { try { File.Delete(files[fileIndex]); } catch { } } } } yield break; }
private void Diagnostics_AssertionFailed(Diagnostics.LogMessage message) { if (this.outputDepugFileStreamWriter == null) { return; } Diagnostics.LogFormat diagnosticsLogFormat = this.DiagnosticsLogFormat; if (diagnosticsLogFormat != Diagnostics.LogFormat.Html) { if (diagnosticsLogFormat == Diagnostics.LogFormat.Text) { this.outputDepugFileStreamWriter.Write("[A] "); this.outputDepugFileStreamWriter.Write(DateTime.Now.ToString("HH:mm:ss:fff")); this.outputDepugFileStreamWriter.Write(" "); this.outputDepugFileStreamWriter.WriteLine(message.Message); this.Diagnostics_OutputDebugStackTrace(message); this.outputDepugFileStreamWriter.WriteLine(); } } else { Diagnostics.LogType logType = Diagnostics.LogType.Assertion; this.outputDepugFileStreamWriter.WriteLine("<p class=\"{1}\"><span class=\"time\">{2}</span><a onclick=\"hide('trace{0}')\">STACK</a>{3}</p>", new object[] { this.DiagnosticsLogCounter, logType.ToString(), DateTime.Now.ToString("HH:mm:ss:fff"), "Assertion Failed: " + message.Message }); this.outputDepugFileStreamWriter.WriteLine("<pre id=\"trace{0}\">", this.DiagnosticsLogCounter); this.Diagnostics_OutputDebugStackTrace(message); int diagnosticsLogCounter = this.DiagnosticsLogCounter; this.DiagnosticsLogCounter = diagnosticsLogCounter + 1; this.outputDepugFileStreamWriter.WriteLine("</pre>"); } this.outputDepugFileStreamWriter.Flush(); }