/[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

--- trunk/AnywhereTS.Logging/Logging.cs	2012/07/16 14:14:09	185
+++ trunk/AnywhereTS.Logging/Logging.cs	2012/07/16 15:00:20	186
@@ -10,39 +10,72 @@
 using System.Windows.Forms;
 using log4net.Appender;
 using System.Linq;
+using log4net.Repository.Hierarchy;
+using log4net.Core;
 
 namespace AnywhereTS
 {
     public static class Logging
     {
+        private static bool configured = false;
         static Logging() { Logging.Initialize(); }
         private static void Initialize()
         {
-            string path = typeof(Logging).Assembly.Location.ToLower().Replace(@"\AnywhereTS.Logging.dll".ToLower(), "");
-            string config = string.Format(@"{0}\{1}", path, "AnywhereTS.Logging.dll.config");
-            //MessageBox.Show(config);
-            FileInfo fi = new FileInfo(config);
-            XmlConfigurator.Configure(fi);
-            Logging.SetLogPath(string.Format(@"{0}\logs", fi.FullName));
+            
+            Assembly t = Assembly.GetExecutingAssembly();
+            FileInfo fi = new FileInfo(t.Location);
+            string path = fi.Directory.FullName;
+            Initialize_FallbackLog(path);
+            FileInfo f_config = new FileInfo(string.Format(@"{0}\{1}", path, "AnywhereTS.Logging.dll.config"));
+            if (f_config.Exists)
+            {
+                XmlConfigurator.Configure(f_config);
+                Logging.UpdateLogPath(string.Format(@"{0}\logs", path));
+                configured = true;
+            }
+            else
+            {
+                configured = false;               
+            }            
+        }
+        private static void Initialize_FallbackLog(string path)
+        {
+            Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();
+            FileAppender appender = new FileAppender();
+            appender.AppendToFile = true;
+            appender.File = string.Format(@"{0}\logs\AnywhereTS.log", path);
+            log4net.Layout.PatternLayout layout = new log4net.Layout.PatternLayout("%date [%thread] %-5level %logger [%property{NDC}] - %message%newline");
+            appender.Layout = layout;
+            appender.Name = "Default";
+            appender.ActivateOptions();
+            hierarchy.Root.AddAppender(appender);
+            hierarchy.Root.Level = Level.All;
+            hierarchy.Configured = true;
+            FallbackLog = LogManager.GetLogger("Default");
         }
-
         #region Log access
-        public static readonly ILog ATSAdminLog = LogManager.GetLogger("AnywhereTS.ATSAmdin");
-        public static readonly ILog TSControlPanelLog = LogManager.GetLogger("AnywhereTS.TSControlPanel");
-        public static readonly ILog DatabaseLog = LogManager.GetLogger("AnywhereTS.DBSupport");
+        public static ILog ATSAdminLog { get { if (!configured) return FallbackLog; return LogManager.GetLogger("AnywhereTS.ATSAmdin"); } }
+        public static ILog TSControlPanelLog { get { if (!configured) return FallbackLog; return LogManager.GetLogger("AnywhereTS.TSControlPanel"); } }
+        public static ILog DatabaseLog { get { if (!configured) return FallbackLog; return LogManager.GetLogger("AnywhereTS.DBSupport"); } }
 
-        public static readonly ILog ATSAdminInstallerLog = LogManager.GetLogger("AnywhereTS.ATSAmdin.Installer");
-        public static readonly ILog TSControlPanelInstallerLog = LogManager.GetLogger("AnywhereTS.TSControlPanel.Installer");
+        public static ILog ATSAdminInstallerLog { get { if (!configured) return FallbackLog; return LogManager.GetLogger("AnywhereTS.ATSAmdin.Installer"); } }
+        public static ILog TSControlPanelInstallerLog { get { if (!configured) return FallbackLog; return LogManager.GetLogger("AnywhereTS.TSControlPanel.Installer"); } }
 
-        public static readonly ILog WizardLog = LogManager.GetLogger("AnywhereTS.Wizard");
-        public static readonly ILog DefaultLog = LogManager.GetLogger("AnywhereTS.DefaultLogger");
+        public static ILog WizardLog { get { if (!configured) return FallbackLog; return LogManager.GetLogger("AnywhereTS.Wizard"); } }
+        public static ILog DefaultLog { get { return FallbackLog; } }
+
+
+        private static ILog FallbackLog;
 
         #endregion
 
         public static void UpdateLogPath() 
         {
-            string path = typeof(Logging).Assembly.Location.ToLower().Replace(@"\AnywhereTS.Logging.dll".ToLower(), "");
-            Logging.UpdateLogPath(path);
+            Assembly t = Assembly.GetExecutingAssembly();
+            FileInfo fi = new FileInfo(t.Location);
+            string path = fi.Directory.FullName;
+
+            Logging.UpdateLogPath(string.Format(@"{0}\logs",path));
         }
         public static void UpdateLogPath(string path) { Logging.SetLogPath(path); }
 

 

  ViewVC Help
Powered by ViewVC 1.1.22