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

Annotation of /trunk/AnywhereTS.Logging/Logging.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 71 - (hide annotations) (download)
Thu Jul 12 21:04:56 2012 UTC (9 years, 3 months ago) by william
File size: 2338 byte(s)
+ add support to push Context Message Back onto the original stack (ie to preserve the stack, after we have peeked and popped all of the context messages)

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

  ViewVC Help
Powered by ViewVC 1.1.22