/[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/14 03:01:07	96
+++ trunk/AnywhereTS.Logging/Logging.cs	2012/07/15 11:21:36	149
@@ -7,20 +7,60 @@
 using log4net.Util;
 using System.Reflection;
 using System.Collections;
+using System.Windows.Forms;
+using log4net.Appender;
+using System.Linq;
 
 namespace AnywhereTS
 {
     public static class Logging
     {
         static Logging() { Logging.Initialize(); }
-        public static void Initialize() { XmlConfigurator.Configure(new FileInfo("AnywhereTS.Logging.dll.config")); }
+        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);
+
+            if (!fi.Exists)
+            {
+                MessageBox.Show(string.Format("Logging Config does not exist!{0}{1}", System.Environment.NewLine, fi.FullName));
+            }
+            else
+            {
+                XmlConfigurator.Configure(new FileInfo(config));
+            }
+        }
 
         #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 readonly ILog ATSAdminInstallerLog = LogManager.GetLogger("AnywhereTS.ATSAmdin.Installer");
+        //public static readonly ILog TSControlPanelInstallerLog = LogManager.GetLogger("AnywhereTS.TSControlPanel.Installer");
         #endregion
 
+
+        public static void SetLogPath(string path)
+        {
+            var fileAppenders = from appender in log4net.LogManager.GetRepository().GetAppenders()
+                                where appender is FileAppender
+                                select appender;
+            fileAppenders.Cast<FileAppender>()
+               .ToList()
+               .ForEach(
+                   fa =>
+                   {
+                       FileInfo fi = new FileInfo(fa.File);
+                       string file = fi.Name;
+                       fa.File = new FileInfo(string.Format(@"{0}\{1}", path, file)).FullName;
+                       fa.ActivateOptions();
+                   }
+               );
+        }
         #region log4net help
         public static List<string> GetMessagesFromThreadContextStack(string RawContextStack)
         {

 

  ViewVC Help
Powered by ViewVC 1.1.22