public void Put(IndentKey key, IndentContext iu) { lock (locker) { indentDictionary[key.GetKey()] = iu; } }
private static void Log(DbgData dd, string format, params object[] args) { IndentKey ik = dd.GetIndentKey(); IndentContext iu = IndentManager.GetInstance().Get(ik); if (format == "<") { if (!iu.Unindent()) { Debug.WriteLine(String.Format("[{0}][{1}]<{2}>Warning : log indent error", project_key, dd.thread_id, iu.GetContextId())); } } string indentStr = iu.GetIndent(); string dbgStr; if (dd.file_name == null) { dbgStr = String.Format("[{0}][{1}]<{2}>{3}{4}[{5}]", project_key, dd.thread_id, iu.GetContextId(), indentStr, dd.method_full_name, dd.thread_name); } else { dbgStr = String.Format("[{0}][{1}]<{2}>{3}{4}({5}){6}[{7}]", project_key, dd.thread_id, iu.GetContextId(), indentStr, dd.file_name, dd.line_number, dd.method_name, dd.thread_name); } string logStr = String.Format(format, args); string finalStr = String.Format("{0} : {1}", dbgStr, logStr); //Console.WriteLine(finalStr); Debug.WriteLine(finalStr); //Debugger.Log(0, null, finalStr); //OutputDebugString(finalStr); if (format == ">") { iu.Indent(); } }
public static void RestoreContext(IndentContext iu) { #if DEBUG StackFrame sf = new StackFrame(1, true); DbgData dd = new DbgData(sf); IndentKey ik = dd.GetIndentKey(); IndentManager.GetInstance().Put(ik, iu); Log(dd, "RestoreContext()"); #endif }
static async Task DoSomethingAsync() { TR.Enter(); IndentContext ic = TR.SaveContextAndShuffle(); await Task.Run(() => { TR.Enter(); TR.Log("Do something async."); TR.Exit(); }); TR.RestoreContext(ic); TR.Log(); TR.Exit(); }
public static IndentContext SaveContextAndShuffle() { #if DEBUG StackFrame sf = new StackFrame(1, true); DbgData dd = new DbgData(sf); Log(dd, "SaveContextAndShuffle()"); IndentKey ik = dd.GetIndentKey(); IndentContext iu = IndentManager.GetInstance().Get(ik); IndentContext copy = new IndentContext(iu); iu.ShuffleContext(); return(copy); #else return(null); #endif }
static void Main(string[] args) { TR.Enter(); DoSomething(); IndentContext ic = TR.SaveContextAndShuffle(); Task t = DoSomethingAsync(); TR.RestoreContext(ic); TR.Log(t.Id); Task t2 = Task.Run(() => DoSomething()); TR.Log(t.Id); t.Wait(); t2.Wait(); TR.Exit(); }
public IndentContext Get(IndentKey key) { string keyStr = key.GetKey(); lock (locker) { if (indentDictionary.ContainsKey(keyStr)) { return(indentDictionary[keyStr]); } else { IndentContext iu = new IndentContext(); indentDictionary.Add(keyStr, iu); return(iu); } } }
public IndentContext(IndentContext iu) { this.indent = iu.indent; this.context_id = iu.context_id; }