/[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/15 08:43:40	147
+++ trunk/AnywhereTS.Logging/Logging.cs	2012/07/15 11:41:39	150
@@ -7,13 +7,24 @@
 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(); }
-        private 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);
+            XmlConfigurator.Configure(fi);
+            Logging.SetLogPath(string.Format(@"{0}\logs", fi.FullName));
+        }
 
         #region Log access
         public static readonly ILog ATSAdminLog = LogManager.GetLogger("AnywhereTS.ATSAmdin");
@@ -24,6 +35,27 @@
         public static readonly ILog TSControlPanelInstallerLog = LogManager.GetLogger("AnywhereTS.TSControlPanel.Installer");
         #endregion
 
+
+        public static void UpdateLogPath(string path) { Logging.SetLogPath(path); }
+
+        private 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