/[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 165 by william, Mon Jul 16 10:19:21 2012 UTC revision 186 by william, Mon Jul 16 15:00:20 2012 UTC
# Line 10  using System.Collections; Line 10  using System.Collections;
10  using System.Windows.Forms;  using System.Windows.Forms;
11  using log4net.Appender;  using log4net.Appender;
12  using System.Linq;  using System.Linq;
13    using log4net.Repository.Hierarchy;
14    using log4net.Core;
15    
16  namespace AnywhereTS  namespace AnywhereTS
17  {  {
18      public static class Logging      public static class Logging
19      {      {
20            private static bool configured = false;
21          static Logging() { Logging.Initialize(); }          static Logging() { Logging.Initialize(); }
22          private static void Initialize()          private static void Initialize()
23          {          {
24              string path = typeof(Logging).Assembly.Location.ToLower().Replace(@"\AnywhereTS.Logging.dll".ToLower(), "");              
25              string config = string.Format(@"{0}\{1}", path, "AnywhereTS.Logging.dll.config");              Assembly t = Assembly.GetExecutingAssembly();
26              //MessageBox.Show(config);              FileInfo fi = new FileInfo(t.Location);
27              FileInfo fi = new FileInfo(config);              string path = fi.Directory.FullName;
28              XmlConfigurator.Configure(fi);              Initialize_FallbackLog(path);
29              Logging.SetLogPath(string.Format(@"{0}\logs", fi.FullName));              FileInfo f_config = new FileInfo(string.Format(@"{0}\{1}", path, "AnywhereTS.Logging.dll.config"));
30                if (f_config.Exists)
31                {
32                    XmlConfigurator.Configure(f_config);
33                    Logging.UpdateLogPath(string.Format(@"{0}\logs", path));
34                    configured = true;
35                }
36                else
37                {
38                    configured = false;              
39                }            
40            }
41            private static void Initialize_FallbackLog(string path)
42            {
43                Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();
44                FileAppender appender = new FileAppender();
45                appender.AppendToFile = true;
46                appender.File = string.Format(@"{0}\logs\AnywhereTS.log", path);
47                log4net.Layout.PatternLayout layout = new log4net.Layout.PatternLayout("%date [%thread] %-5level %logger [%property{NDC}] - %message%newline");
48                appender.Layout = layout;
49                appender.Name = "Default";
50                appender.ActivateOptions();
51                hierarchy.Root.AddAppender(appender);
52                hierarchy.Root.Level = Level.All;
53                hierarchy.Configured = true;
54                FallbackLog = LogManager.GetLogger("Default");
55          }          }
   
56          #region Log access          #region Log access
57          public static readonly ILog ATSAdminLog = LogManager.GetLogger("AnywhereTS.ATSAmdin");          public static ILog ATSAdminLog { get { if (!configured) return FallbackLog; return LogManager.GetLogger("AnywhereTS.ATSAmdin"); } }
58          public static readonly ILog TSControlPanelLog = LogManager.GetLogger("AnywhereTS.TSControlPanel");          public static ILog TSControlPanelLog { get { if (!configured) return FallbackLog; return LogManager.GetLogger("AnywhereTS.TSControlPanel"); } }
59          public static readonly ILog DatabaseLog = LogManager.GetLogger("AnywhereTS.DBSupport");          public static ILog DatabaseLog { get { if (!configured) return FallbackLog; return LogManager.GetLogger("AnywhereTS.DBSupport"); } }
60    
61          public static readonly ILog ATSAdminInstallerLog = LogManager.GetLogger("AnywhereTS.ATSAmdin.Installer");          public static ILog ATSAdminInstallerLog { get { if (!configured) return FallbackLog; return LogManager.GetLogger("AnywhereTS.ATSAmdin.Installer"); } }
62          public static readonly ILog TSControlPanelInstallerLog = LogManager.GetLogger("AnywhereTS.TSControlPanel.Installer");          public static ILog TSControlPanelInstallerLog { get { if (!configured) return FallbackLog; return LogManager.GetLogger("AnywhereTS.TSControlPanel.Installer"); } }
63    
64          public static readonly ILog WizardLog = LogManager.GetLogger("AnywhereTS.Wizard");          public static ILog WizardLog { get { if (!configured) return FallbackLog; return LogManager.GetLogger("AnywhereTS.Wizard"); } }
65          public static readonly ILog DefaultLog = LogManager.GetLogger("AnywhereTS.DefaultLogger");          public static ILog DefaultLog { get { return FallbackLog; } }
66    
67    
68            private static ILog FallbackLog;
69    
70          #endregion          #endregion
71    
72          public static void UpdateLogPath()          public static void UpdateLogPath()
73          {          {
74              string path = typeof(Logging).Assembly.Location.ToLower().Replace(@"\AnywhereTS.Logging.dll".ToLower(), "");              Assembly t = Assembly.GetExecutingAssembly();
75              Logging.UpdateLogPath(path);              FileInfo fi = new FileInfo(t.Location);
76                string path = fi.Directory.FullName;
77    
78                Logging.UpdateLogPath(string.Format(@"{0}\logs",path));
79          }          }
80          public static void UpdateLogPath(string path) { Logging.SetLogPath(path); }          public static void UpdateLogPath(string path) { Logging.SetLogPath(path); }
81    

Legend:
Removed from v.165  
changed lines
  Added in v.186

  ViewVC Help
Powered by ViewVC 1.1.22