diff --git a/product/roundhouse/infrastructure.app/ApplicationConfiguraton.cs b/product/roundhouse/infrastructure.app/ApplicationConfiguraton.cs index c444d2fa..405efd4b 100644 --- a/product/roundhouse/infrastructure.app/ApplicationConfiguraton.cs +++ b/product/roundhouse/infrastructure.app/ApplicationConfiguraton.cs @@ -17,6 +17,7 @@ namespace roundhouse.infrastructure.app using folders; using infrastructure.logging; using infrastructure.logging.custom; + using logging; using migrators; using resolvers; using StructureMap; @@ -46,7 +47,7 @@ public static void set_defaults_if_properties_are_not_set(ConfigurationPropertyH if (string.IsNullOrEmpty(configuration_property_holder.AlterDatabaseFolderName)) { configuration_property_holder.AlterDatabaseFolderName = ApplicationParameters.default_alter_database_folder_name; - } + } if (string.IsNullOrEmpty(configuration_property_holder.UpFolderName)) { configuration_property_holder.UpFolderName = ApplicationParameters.default_up_folder_name; @@ -143,6 +144,7 @@ public static void build_the_container(ConfigurationPropertyHolder configuration { Container.initialize_with(null); Container.initialize_with(build_items_for_container(configuration_property_holder)); + initialize_file_log_appender(); } private static InversionContainer build_items_for_container(ConfigurationPropertyHolder configuration_property_holder) @@ -200,5 +202,12 @@ private static Logger GetMultiLogger(ConfigurationPropertyHolder configuration_p return new MultipleLogger(loggers); } + + private static void initialize_file_log_appender() + { + var known_folders = Container.get_an_instance_of(); + + Log4NetAppender.set_file_appender(known_folders.change_drop.folder_full_path); + } } } \ No newline at end of file diff --git a/product/roundhouse/infrastructure.app/builders/KnownFoldersBuilder.cs b/product/roundhouse/infrastructure.app/builders/KnownFoldersBuilder.cs index 48dd3f97..abb2b207 100644 --- a/product/roundhouse/infrastructure.app/builders/KnownFoldersBuilder.cs +++ b/product/roundhouse/infrastructure.app/builders/KnownFoldersBuilder.cs @@ -45,7 +45,6 @@ private static string combine_items_into_one_path(FileSystemAccess file_system, return file_system.combine_paths(paths); } - private static string get_run_date_time_string() { return string.Format("{0:yyyyMMdd_HHmmss_ffff}", DateTime.Now); diff --git a/product/roundhouse/infrastructure.app/logging/Log4NetAppender.cs b/product/roundhouse/infrastructure.app/logging/Log4NetAppender.cs index b80609e7..257ab0ad 100644 --- a/product/roundhouse/infrastructure.app/logging/Log4NetAppender.cs +++ b/product/roundhouse/infrastructure.app/logging/Log4NetAppender.cs @@ -10,18 +10,18 @@ namespace roundhouse.infrastructure.app.logging { public class Log4NetAppender { - private static readonly ILog the_logger = LogManager.GetLogger(typeof (Log4NetAppender)); + private static readonly ILog the_logger = LogManager.GetLogger(typeof(Log4NetAppender)); private static bool used_merged = true; - + private static IAppender set_up_console_appender() { ConsoleAppender appender = new ConsoleAppender(); appender.Name = "ConsoleAppender"; - + PatternLayout pattern_layout = new PatternLayout("%message%newline"); pattern_layout.ActivateOptions(); appender.Layout = pattern_layout; - + appender.ActivateOptions(); return appender; @@ -37,7 +37,7 @@ private static IAppender set_up_rolling_file_appender() appender.AppendToFile = false; appender.StaticLogFileName = true; - PatternLayout pattern_layout= new PatternLayout("%date [%-5level] - %message%newline"); + PatternLayout pattern_layout = new PatternLayout("%date [%-5level] - %message%newline"); pattern_layout.ActivateOptions(); appender.Layout = pattern_layout; @@ -50,7 +50,7 @@ public static void configure() { //ILoggerRepository log_repository = LogManager.GetRepository(Assembly.GetCallingAssembly()); //log_repository.Threshold = Level.Info; - + //BasicConfigurator.Configure(log_repository, set_up_console_appender()); //BasicConfigurator.Configure(log_repository,set_up_rolling_file_appender()); @@ -58,23 +58,23 @@ public static void configure() string assembly_name = ApplicationParameters.log4net_configuration_assembly; Stream xml_config_stream; - + try { xml_config_stream = Assembly.Load(ApplicationParameters.get_merged_assembly_name()).GetManifestResourceStream(ApplicationParameters.log4net_configuration_resource); - - if (xml_config_stream == null) - { - throw new NullReferenceException("Failed to load xml configuration for log4net, consider that assemblies was not merged"); - } + + if (xml_config_stream == null) + { + throw new NullReferenceException("Failed to load xml configuration for log4net, consider that assemblies was not merged"); + } } catch (Exception) { used_merged = false; xml_config_stream = Assembly.Load(assembly_name).GetManifestResourceStream(ApplicationParameters.log4net_configuration_resource); } - - XmlConfigurator.Configure(xml_config_stream); + + XmlConfigurator.Configure(xml_config_stream); the_logger.DebugFormat("Configured {0} from assembly {1}", ApplicationParameters.log4net_configuration_resource, used_merged ? ApplicationParameters.get_merged_assembly_name() : assembly_name); } @@ -93,7 +93,7 @@ public static void configure_without_console() try { xml_config_stream = Assembly.Load(ApplicationParameters.get_merged_assembly_name()).GetManifestResourceStream(ApplicationParameters.log4net_configuration_resource_no_console); - + } catch (Exception) { @@ -106,5 +106,34 @@ public static void configure_without_console() the_logger.DebugFormat("Configured {0} from assembly {1}", ApplicationParameters.log4net_configuration_resource_no_console, used_merged ? ApplicationParameters.get_merged_assembly_name() : assembly_name); } + private static bool already_configured_file_appender = false; + + public static void set_file_appender(string output_directory) + { + if (!already_configured_file_appender) + { + already_configured_file_appender = true; + var log = LogManager.GetLogger("roundhouse"); + var l = (log4net.Repository.Hierarchy.Logger)log.Logger; + + var layout = new PatternLayout + { + ConversionPattern = "%date [%-5level] - %message%newline" + }; + layout.ActivateOptions(); + + var app = new RollingFileAppender + { + Name = "RollingLogFileAppender", + File = Path.Combine(Path.GetFullPath(output_directory), "roundhouse.changes.log"), + Layout = layout, + AppendToFile = false + }; + app.ActivateOptions(); + + l.AddAppender(app); + } + } + } } \ No newline at end of file diff --git a/product/roundhouse/infrastructure.app/logging/log4net.config.no.console.xml b/product/roundhouse/infrastructure.app/logging/log4net.config.no.console.xml index 00b48774..07b35dae 100644 --- a/product/roundhouse/infrastructure.app/logging/log4net.config.no.console.xml +++ b/product/roundhouse/infrastructure.app/logging/log4net.config.no.console.xml @@ -1,24 +1,8 @@  - - - - - - - - - - - - - - - - @@ -30,4 +14,8 @@ + + + + \ No newline at end of file diff --git a/product/roundhouse/infrastructure.app/logging/log4net.config.xml b/product/roundhouse/infrastructure.app/logging/log4net.config.xml index 633bf8e7..17903cbc 100644 --- a/product/roundhouse/infrastructure.app/logging/log4net.config.xml +++ b/product/roundhouse/infrastructure.app/logging/log4net.config.xml @@ -24,53 +24,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -87,7 +40,6 @@ - \ No newline at end of file diff --git a/product/roundhouse/runners/RoundhouseMigrationRunner.cs b/product/roundhouse/runners/RoundhouseMigrationRunner.cs index ec218acd..d11b5a0a 100644 --- a/product/roundhouse/runners/RoundhouseMigrationRunner.cs +++ b/product/roundhouse/runners/RoundhouseMigrationRunner.cs @@ -212,7 +212,7 @@ public void run() finally { database_migrator.database.Dispose(); - copy_log_file_to_change_drop_folder(); + //copy_log_file_to_change_drop_folder(); } } @@ -294,27 +294,27 @@ private void copy_to_change_drop_folder(string sql_file_ran, Folder migration_fo file_system.file_copy_unsafe(sql_file_ran, destination_file, true); } - private void copy_log_file_to_change_drop_folder() - { - string log_file = ApplicationParameters.logging_file; - string log_file_name = file_system.get_file_name_from(log_file); - - try - { - string destination_file = file_system.combine_paths(known_folders.change_drop.folder_full_path, log_file_name); - file_system.file_copy(log_file, destination_file, true); - } - catch (Exception exception) - { - Log.bound_to(this). - log_an_error_event_containing("{0} encountered an error:{1}{2}", - ApplicationParameters.name, - System.Environment.NewLine, - exception.to_string() - ); - } - - } + //private void copy_log_file_to_change_drop_folder() + //{ + // string log_file = ApplicationParameters.logging_file; + // string log_file_name = file_system.get_file_name_from(log_file); + + // try + // { + // string destination_file = file_system.combine_paths(known_folders.change_drop.folder_full_path, log_file_name); + // file_system.file_copy(log_file, destination_file, true); + // } + // catch (Exception exception) + // { + // Log.bound_to(this). + // log_an_error_event_containing("{0} encountered an error:{1}{2}", + // ApplicationParameters.name, + // System.Environment.NewLine, + // exception.to_string() + // ); + // } + + //} } } \ No newline at end of file