/[AnywhereTS-MSSQL]/trunk/AnywhereTS.Logging/Logging.cs
ViewVC logotype

Diff of /trunk/AnywhereTS.Logging/Logging.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 36 by william, Thu Jul 12 11:35:07 2012 UTC revision 96 by william, Sat Jul 14 03:01:07 2012 UTC
# Line 4  using System.Text; Line 4  using System.Text;
4  using log4net.Config;  using log4net.Config;
5  using log4net;  using log4net;
6  using System.IO;  using System.IO;
7    using log4net.Util;
8    using System.Reflection;
9    using System.Collections;
10    
11  namespace AnywhereTS  namespace AnywhereTS
12  {  {
13      public static class Logging      public static class Logging
14      {      {
15          static Logging() { Logging.Initialize(); }          static Logging() { Logging.Initialize(); }
16          private static void Initialize() { XmlConfigurator.Configure(new FileInfo("AnywhereTS.Logging.dll.config")); }          public static void Initialize() { XmlConfigurator.Configure(new FileInfo("AnywhereTS.Logging.dll.config")); }
17    
18          #region Log access          #region Log access
19          public static readonly ILog ATSAdminLog = LogManager.GetLogger("AnywhereTS.ATSAmdin");          public static readonly ILog ATSAdminLog = LogManager.GetLogger("AnywhereTS.ATSAmdin");
20            public static readonly ILog TSControlPanelLog = LogManager.GetLogger("AnywhereTS.TSControlPanel");
21            public static readonly ILog DatabaseLog = LogManager.GetLogger("AnywhereTS.DBSupport");
22            #endregion
23    
24            #region log4net help
25            public static List<string> GetMessagesFromThreadContextStack(string RawContextStack)
26            {
27                try
28                {
29                    ThreadContextStack tc = ThreadContext.Stacks[RawContextStack.ToUpper()];
30                    if (tc == null) { return new List<string>(); }
31                    else { return GetMessagesFromThreadContextStack(tc); }
32                }
33                catch { return new List<string>(); }
34            }
35            public static List<string> GetMessagesFromThreadContextStack(ThreadContextStack rawTCS)
36            {
37                Type t = typeof(ThreadContextStack);
38                //ConstructorInfo ci = t.GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[0], null);
39                //ThreadContextStack tmpRawTCS = null;
40                //tmpRawTCS = (ThreadContextStack)ci.Invoke(null);
41                List<string> stObjects = new List<string>();
42                ThreadContextStack context = (rawTCS as ThreadContextStack);
43                for (int i = 0; i < context.Count; i++)
44                {
45                    MethodInfo mi = t.GetMethod("GetFullMessage", BindingFlags.NonPublic | BindingFlags.Instance);
46                    string message = mi.Invoke(context, null).ToString();
47                    stObjects.Add(message);
48                    context.Pop();
49                }
50                stObjects.Reverse();
51                rawTCS.Clear();
52                // push the popped Context message back onto the original ContextStack
53                foreach (string stObject in stObjects) { rawTCS.Push(stObject); }
54                return stObjects;
55            }
56          #endregion          #endregion
57      }      }
58  }  }

Legend:
Removed from v.36  
changed lines
  Added in v.96

  ViewVC Help
Powered by ViewVC 1.1.22