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

Contents of /trunk/AnywhereTS.Logging/Logging.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 86 - (show annotations) (download)
Fri Jul 13 21:13:27 2012 UTC (8 years ago) by william
File size: 2435 byte(s)
+ Admin: add referens to DBSupport
+ add logging support for database

1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using log4net.Config;
5 using log4net;
6 using System.IO;
7 using log4net.Util;
8 using System.Reflection;
9 using System.Collections;
10
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 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
57 }
58 }

  ViewVC Help
Powered by ViewVC 1.1.22