/[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 86 - (hide annotations) (download)
Fri Jul 13 21:13:27 2012 UTC (9 years, 4 months ago) by william
File size: 2435 byte(s)
+ Admin: add referens to DBSupport
+ add logging support for database

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 86 public static readonly ILog DatabaseLog = LogManager.GetLogger("AnywhereTS.DBSupport");
22 william 36 #endregion
23 william 70
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 william 71 catch { return new List<string>(); }
34 william 70 }
35     public static List<string> GetMessagesFromThreadContextStack(ThreadContextStack rawTCS)
36     {
37 william 71 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 william 70 }
56     #endregion
57 william 36 }
58     }

  ViewVC Help
Powered by ViewVC 1.1.22