ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/AnywhereTS-MSSQL/trunk/AnywhereTS.Logging/Logging.cs
(Generate patch)

Comparing trunk/AnywhereTS.Logging/Logging.cs (file contents):
Revision 69 by william, Thu Jul 12 14:32:21 2012 UTC vs.
Revision 70 by william, Thu Jul 12 20:47:35 2012 UTC

--- trunk/AnywhereTS.Logging/Logging.cs	2012/07/12 20:06:53	69
+++ trunk/AnywhereTS.Logging/Logging.cs	2012/07/12 20:47:35	70
@@ -4,6 +4,9 @@ using System.Text;
 using log4net.Config;
 using log4net;
 using System.IO;
+using log4net.Util;
+using System.Reflection;
+using System.Collections;
 
 namespace AnywhereTS
 {
@@ -16,5 +19,35 @@ namespace AnywhereTS
         public static readonly ILog ATSAdminLog = LogManager.GetLogger("AnywhereTS.ATSAmdin");
         public static readonly ILog TSControlPanelLog = LogManager.GetLogger("AnywhereTS.TSControlPanel");
         #endregion
+
+        #region log4net help
+        public static List<string> GetMessagesFromThreadContextStack(string RawContextStack)
+        {
+            try
+            {
+                ThreadContextStack tc = ThreadContext.Stacks[RawContextStack.ToUpper()];
+                if (tc == null) { return new List<string>(); }
+                else { return GetMessagesFromThreadContextStack(tc); }
+            }
+            catch { return new List<string>(); }            
+        }
+        public static List<string> GetMessagesFromThreadContextStack(ThreadContextStack rawTCS)
+        {
+            ThreadContextStack oldrawTCS = rawTCS;
+            List<string> stack_objects = new List<string>();
+           
+                ThreadContextStack context = (rawTCS as ThreadContextStack);
+                for (int i = 0; i < context.Count; i++)
+                {
+                    Type t = typeof(ThreadContextStack);
+                    MethodInfo mi = t.GetMethod("GetFullMessage", BindingFlags.NonPublic | BindingFlags.Instance);
+                    string message = mi.Invoke(context, null).ToString();
+                    stack_objects.Add(message);
+                    context.Pop();
+                }
+                rawTCS = oldrawTCS;            
+            return stack_objects;
+        }
+        #endregion
     }
 }