diff --git a/Applications/CxAnalytixDaemon/Program.cs b/Applications/CxAnalytixDaemon/Program.cs index c539ff68..ac62c180 100644 --- a/Applications/CxAnalytixDaemon/Program.cs +++ b/Applications/CxAnalytixDaemon/Program.cs @@ -4,10 +4,6 @@ using System.Threading.Tasks; -[assembly: CxRestClient.IO.NetworkTraceLog()] -[assembly: CxAnalytix.Extensions.LogTrace()] -[assembly: log4net.Config.XmlConfigurator(ConfigFile = "cxanalytix.log4net", Watch = true)] - namespace CxAnalytixDaemon { class Program diff --git a/Libs/Configuration/Impls/Config.cs b/Libs/Configuration/Impls/Config.cs index 9e256a32..0141d564 100644 --- a/Libs/Configuration/Impls/Config.cs +++ b/Libs/Configuration/Impls/Config.cs @@ -4,7 +4,7 @@ using System; using System.Configuration; using System.IO; -using System.Reflection; + namespace CxAnalytix.Configuration.Impls { @@ -13,9 +13,6 @@ public class Config private static System.Configuration.Configuration _cfgManager; private static ILog _log = LogManager.GetLogger(typeof (Config) ); private static readonly String CONFIG_FILE_NAME = "cxanalytix.config"; - private static readonly String CONFIG_PATH_VARIABLE = "CXANALYTIX_CONFIG_PATH"; - private static readonly String DEFAULT_FOLDER_NAME = "cxanalytix"; - private static readonly String DEFAULT_LINUX_PATH = $"/etc/{DEFAULT_FOLDER_NAME}"; private static IContainer _configDI; @@ -23,7 +20,7 @@ public class Config static Config() { ExeConfigurationFileMap map = new ExeConfigurationFileMap(); - map.ExeConfigFilename = FindConfigFilePath(); + map.ExeConfigFilename = ConfigPathResolver.ResolveConfigFilePath(CONFIG_FILE_NAME); _log.DebugFormat("Loading configuration from [{0}]", map.ExeConfigFilename); if (!File.Exists(map.ExeConfigFilename)) @@ -52,35 +49,6 @@ public static T GetConfig() } - private static String FindConfigFilePath() - { - String cwd = Path.Combine(Directory.GetCurrentDirectory(), CONFIG_FILE_NAME); - - if (File.Exists(cwd)) - return cwd; - - if (Environment.GetEnvironmentVariables()[CONFIG_PATH_VARIABLE] != null) - { - String env = Path.Combine(Environment.GetEnvironmentVariables()[CONFIG_PATH_VARIABLE] as String, CONFIG_FILE_NAME); - if (File.Exists(env)) - return env; - } - - String os = String.Empty; - - if (OperatingSystem.IsWindows()) - os = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), DEFAULT_FOLDER_NAME, CONFIG_FILE_NAME); - else - os = Path.Combine(DEFAULT_LINUX_PATH, CONFIG_FILE_NAME); - - if (File.Exists(os)) - return os; - - throw new FileNotFoundException($"Configuration file {CONFIG_FILE_NAME} could not be located."); - } - - - private static void EncryptSensitiveSections() { foreach (ConfigurationSection section in _cfgManager.Sections) diff --git a/Libs/Configuration/Utils/ConfigPathResolver.cs b/Libs/Configuration/Utils/ConfigPathResolver.cs new file mode 100644 index 00000000..1fa8bbf1 --- /dev/null +++ b/Libs/Configuration/Utils/ConfigPathResolver.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CxAnalytix.Configuration.Utils +{ + public class ConfigPathResolver + { + private static readonly String CONFIG_PATH_VARIABLE = "CXANALYTIX_CONFIG_PATH"; + private static readonly String DEFAULT_FOLDER_NAME = "cxanalytix"; + private static readonly String DEFAULT_LINUX_PATH = $"/etc/{DEFAULT_FOLDER_NAME}"; + + public static String ResolveConfigFilePath(String fileName) + { + String cwd = Path.Combine(Directory.GetCurrentDirectory(), fileName); + + if (File.Exists(cwd)) + return cwd; + + if (Environment.GetEnvironmentVariables()[CONFIG_PATH_VARIABLE] != null) + { + String env = Path.Combine(Environment.GetEnvironmentVariables()[CONFIG_PATH_VARIABLE] as String, fileName); + if (File.Exists(env)) + return env; + } + + String os = String.Empty; + + if (OperatingSystem.IsWindows()) + os = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), DEFAULT_FOLDER_NAME, fileName); + else + os = Path.Combine(DEFAULT_LINUX_PATH, fileName); + + if (File.Exists(os)) + return os; + + throw new FileNotFoundException($"Configuration file {fileName} could not be located."); + } + } +} diff --git a/Libs/Executive/ExecuteOnce.cs b/Libs/Executive/ExecuteOnce.cs index d470457e..b6303e98 100644 --- a/Libs/Executive/ExecuteOnce.cs +++ b/Libs/Executive/ExecuteOnce.cs @@ -10,10 +10,10 @@ using Autofac.Core.Registration; using SDK.Modules; using CxAnalytix.Exceptions; +using CxAnalytix.Configuration.Utils; [assembly: CxRestClient.IO.NetworkTraceLog()] [assembly: CxAnalytix.Extensions.LogTrace()] -[assembly: log4net.Config.XmlConfigurator(ConfigFile = "cxanalytix.log4net", Watch = true)] namespace CxAnalytix.Executive @@ -23,6 +23,8 @@ namespace CxAnalytix.Executive public class ExecuteOnce { + private static readonly String LOG_CONFIG_FILE_NAME = "cxanalytix.log4net"; + private static IContainer _xformersContainer; protected static CxAnalytixService Service => Config.GetConfig(); @@ -34,6 +36,8 @@ public class ExecuteOnce static ExecuteOnce() { + var l4net_config = new FileInfo(ConfigPathResolver.ResolveConfigFilePath (LOG_CONFIG_FILE_NAME) ); + log4net.Config.XmlConfigurator.Configure(l4net_config); var builder = new ContainerBuilder(); builder.RegisterAssemblyModules(typeof(ITransformer), Reflection.GetOutputAssemblies());