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 |
|
23 |
public static readonly ILog ATSAdminInstallerLog = LogManager.GetLogger("AnywhereTS.ATSAmdin.Installer"); |
24 |
public static readonly ILog TSControlPanelInstallerLog = LogManager.GetLogger("AnywhereTS.TSControlPanel.Installer"); |
25 |
#endregion |
26 |
|
27 |
#region log4net help |
28 |
public static List<string> GetMessagesFromThreadContextStack(string RawContextStack) |
29 |
{ |
30 |
try |
31 |
{ |
32 |
ThreadContextStack tc = ThreadContext.Stacks[RawContextStack.ToUpper()]; |
33 |
if (tc == null) { return new List<string>(); } |
34 |
else { return GetMessagesFromThreadContextStack(tc); } |
35 |
} |
36 |
catch { return new List<string>(); } |
37 |
} |
38 |
public static List<string> GetMessagesFromThreadContextStack(ThreadContextStack rawTCS) |
39 |
{ |
40 |
Type t = typeof(ThreadContextStack); |
41 |
//ConstructorInfo ci = t.GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[0], null); |
42 |
//ThreadContextStack tmpRawTCS = null; |
43 |
//tmpRawTCS = (ThreadContextStack)ci.Invoke(null); |
44 |
List<string> stObjects = new List<string>(); |
45 |
ThreadContextStack context = (rawTCS as ThreadContextStack); |
46 |
for (int i = 0; i < context.Count; i++) |
47 |
{ |
48 |
MethodInfo mi = t.GetMethod("GetFullMessage", BindingFlags.NonPublic | BindingFlags.Instance); |
49 |
string message = mi.Invoke(context, null).ToString(); |
50 |
stObjects.Add(message); |
51 |
context.Pop(); |
52 |
} |
53 |
stObjects.Reverse(); |
54 |
rawTCS.Clear(); |
55 |
// push the popped Context message back onto the original ContextStack |
56 |
foreach (string stObject in stObjects) { rawTCS.Push(stObject); } |
57 |
return stObjects; |
58 |
} |
59 |
#endregion |
60 |
} |
61 |
} |