Skip to content

Commit

Permalink
removing the temporary log location - #7
Browse files Browse the repository at this point in the history
  • Loading branch information
ferventcoder committed Aug 16, 2011
1 parent f4bb6d3 commit 9250541
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 103 deletions.
11 changes: 10 additions & 1 deletion product/roundhouse/infrastructure.app/ApplicationConfiguraton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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<KnownFolders>();

Log4NetAppender.set_file_appender(known_folders.change_drop.folder_full_path);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
59 changes: 44 additions & 15 deletions product/roundhouse/infrastructure.app/logging/Log4NetAppender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -50,31 +50,31 @@ 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());

//todo: merge assembly is the default now.

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);
}
Expand All @@ -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)
{
Expand All @@ -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);
}
}

}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
<?xml version="1.0"?>
<log4net>

<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="C:\Temp\RoundhousE\roundhouse.changes.log"/>
<appendToFile value="false"/>
<maxSizeRollBackups value="10"/>
<maximumFileSize value="1MB"/>
<rollingStyle value="Size"/>
<staticLogFileName value="true"/>
<layout type="log4net.Layout.PatternLayout">
<!--<header value="[Header]&#13;&#10;" />-->
<!--<footer value="[Footer]&#13;&#10;" />-->
<!--<conversionPattern value="%date [%thread] %-5level %logger [%ndc] - %message%newline" />-->
<conversionPattern value="%date [%-5level] - %message%newline"/>
</layout>
</appender>

<root>
<level value="INFO"/>
<appender-ref ref="RollingLogFileAppender"/>
</root>

<!--Standard NHibernate Logging Settings-->
Expand All @@ -30,4 +14,8 @@
<level value="ERROR"/>
</logger>

<logger name="roundhouse">
<level value="INFO"/>
</logger>

</log4net>
48 changes: 0 additions & 48 deletions product/roundhouse/infrastructure.app/logging/log4net.config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,53 +24,6 @@
</layout>
</appender>

<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<!--<conversionPattern value="%date [%thread] %-5level %logger [%ndc] - %message%newline" />-->
<conversionPattern value="%message%newline"/>
</layout>
</appender>

<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="C:\Temp\RoundhousE\roundhouse.changes.log"/>
<appendToFile value="false"/>
<maxSizeRollBackups value="10"/>
<maximumFileSize value="1MB"/>
<rollingStyle value="Size"/>
<staticLogFileName value="true"/>
<layout type="log4net.Layout.PatternLayout">
<!--<header value="[Header]&#13;&#10;" />-->
<!--<footer value="[Footer]&#13;&#10;" />-->
<!--<conversionPattern value="%date [%thread] %-5level %logger [%ndc] - %message%newline" />-->
<conversionPattern value="%date [%-5level] - %message%newline"/>
</layout>
</appender>

<appender name="ErrorSmtpAppender" type="log4net.Appender.SmtpAppender">
<to value="[email protected]"/>
<from value="[email protected]"/>
<subject value="RoundhousE ERRORS - LOCAL DEBUG"/>
<smtpHost value="localhost"/>
<bufferSize value="2"/>
<lossy value="true"/>
<evaluator type="log4net.Core.LevelEvaluator">
<threshold value="ERROR"/>
</evaluator>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%newline%date [%thread] %-5level %logger - %message%newline"/>
<!--<conversionPattern value="%newline%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />-->
</layout>
</appender>

<appender name="ErrorEventLogAppender" type="log4net.Appender.EventLogAppender">
<LogName value="Application"/>
<ApplicationName value="RoundhousE"/>
<threshold value="ERROR"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger - %message%newline%newline"/>
</layout>
</appender>

<root>
<level value="INFO"/>
<appender-ref ref="ColoredConsoleAppender"/>
Expand All @@ -87,7 +40,6 @@

<logger name="roundhouse">
<level value="INFO"/>
<appender-ref ref="RollingLogFileAppender"/>
</logger>

</log4net>
44 changes: 22 additions & 22 deletions product/roundhouse/runners/RoundhouseMigrationRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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()
// );
// }

//}

}
}

0 comments on commit 9250541

Please sign in to comment.