Changeset 839c8d0d8152…
Parent 3d92bf72278f…
by
Changes to 5 files · Browse files at 839c8d0d8152 Showing diff from parent 3d92bf72278f Diff from another changeset...
@@ -19,37 +19,26 @@ {
private int _widthFirstColumn = 5;
private bool _trace = false;
- private log4net.ILog _logger = log4net.LogManager.GetLogger("Migrator");
public ConsoleLogger(bool trace)
{
_trace = trace;
- var layout = new log4net.Layout.PatternLayout("%message");
- (_logger.Logger as log4net.Repository.Hierarchy.Logger).AddAppender(new log4net.Appender.ConsoleAppender(layout));
- (_logger.Logger as log4net.Repository.Hierarchy.Logger).Level = log4net.Core.Level.All;
-
-
}
public void Started(int currentVersion, int finalVersion)
{
-
- _logger.InfoFormat("Migrating from Current Version: {0} to version {1}", currentVersion, finalVersion);
-
+ if (_trace)
+ Console.WriteLine("Migrating from Current Version: {0} to version {1}", currentVersion, finalVersion);
+ else
+ Console.Write("Migrating from {0} to {1}: ", currentVersion, finalVersion);
}
public void MigrateUp(int version, string migrationName)
{
if (this._trace)
- {
-
- _logger.InfoFormat("{0} {1}", version.ToString().PadLeft(_widthFirstColumn), migrationName);
- }
-
+ Console.WriteLine("{0} {1}", version.ToString().PadLeft(_widthFirstColumn), migrationName);
else
- {
- _logger.InfoFormat("..{0}", version.ToString());
- }
+ Console.Write("..{0}");
}
public void MigrateDown(int version, string migrationName)
|
|
|
@@ -0,0 +1,112 @@ + using System;
+using System.Collections.Generic;
+using System.Text;
+using log4net.Core;
+
+namespace Migrator.Loggers
+{
+ public class Log4NetLogger : ILogger
+ {
+ #region ILogger Members
+
+ private log4net.ILog _logger = log4net.LogManager.GetLogger("Migrator.Messages");
+ private log4net.ILog _quickLogger = log4net.LogManager.GetLogger("Migrator.QuickLogger");
+ private log4net.ILog _migrateUp = log4net.LogManager.GetLogger("Migrator.Migrate.Up");
+ private log4net.ILog _migrateDown = log4net.LogManager.GetLogger("Migrator.Migrate.Down");
+
+
+
+ public Log4NetLogger()
+ {
+
+
+ }
+
+ public void Started(int currentVersion, int finalVersion)
+ {
+
+ _logger.InfoFormat("Started migrating from version {0} to version {1}.", currentVersion, finalVersion);
+ _quickLogger.InfoFormat("Started migrating from version {0} to version {1}. \n", currentVersion, finalVersion);
+ }
+
+ public void MigrateUp(int version, string migrationName)
+ {
+
+ LoggingEvent loggingEvent = new LoggingEvent(
+ typeof(Log4NetLogger),
+ _migrateUp.Logger.Repository,
+ _migrateUp.Logger.Name,
+ Level.Info,
+ string.Format("Migrating up to version {0} [{1}].", version, migrationName),
+ null);
+
+ loggingEvent.Properties["version"] = version;
+ loggingEvent.Properties["migrationName"] = migrationName;
+
+ _migrateUp.Logger.Log(loggingEvent);
+
+
+ }
+
+ public void MigrateDown(int version, string migrationName)
+ {
+ LoggingEvent loggingEvent = new LoggingEvent(
+ typeof(Log4NetLogger),
+ _migrateDown.Logger.Repository,
+ _migrateDown.Logger.Name,
+ Level.Info,
+ string.Format("Migrating down to version {0} [{1}].", version, migrationName),
+ null);
+
+ loggingEvent.Properties["version"] = version;
+ loggingEvent.Properties["migrationName"] = migrationName;
+
+ _migrateDown.Logger.Log(loggingEvent);
+ }
+
+ public void Skipping(int version)
+ {
+ _logger.WarnFormat("Skipping version {0}", version);
+ }
+
+ public void RollingBack(int originalVersion)
+ {
+ _logger.WarnFormat("Rolling back to version {0}", originalVersion);
+ }
+
+ public void Exception(int version, string migrationName, Exception ex)
+ {
+ string message = String.Format("Exception thrown in migration {0} version {1}", migrationName, version);
+ _logger.Fatal(message, ex);
+ }
+
+ public void Exception(string format, Exception ex, params object[] formatItems)
+ {
+ string message = String.Format(format, formatItems);
+ _logger.Fatal(message, ex);
+ }
+
+ public void Finished(int originalVersion, int currentVersion)
+ {
+ _logger.InfoFormat("Finished migrating from version {0} to version {1}.", originalVersion, currentVersion);
+ _quickLogger.InfoFormat("Finished migrating from version {0} to version {1}. \n", originalVersion, currentVersion);
+ }
+
+ public void Log(string format, params object[] args)
+ {
+ _logger.InfoFormat(format, args);
+ }
+
+ public void Warn(string format, params object[] args)
+ {
+ _logger.WarnFormat(format,args);
+ }
+
+ public void Trace(string format, params object[] args)
+ {
+ _logger.DebugFormat(format, args);
+ }
+
+ #endregion
+ }
+}
|
@@ -54,22 +54,22 @@ { }
public Migrator(string provider, string connectionString, Assembly migrationAssembly, bool trace)
- : this(CreateProvider(provider, connectionString), migrationAssembly, new ConsoleLogger(trace))
+ : this(CreateProvider(provider, connectionString), migrationAssembly, new Log4NetLogger())
{ }
public Migrator(string provider, string connectionString, Assembly migrationAssembly)
- : this(CreateProvider(provider, connectionString), migrationAssembly, new ConsoleLogger(false))
+ : this(CreateProvider(provider, connectionString), migrationAssembly, new Log4NetLogger())
{ }
public Migrator(TransformationProvider provider, Assembly migrationAssembly, bool trace)
- : this(provider, migrationAssembly, new ConsoleLogger(trace))
+ : this(provider, migrationAssembly, new Log4NetLogger())
{ }
/// <summary>
/// Runs Migrations in the executing <c>Assembly</c>
/// </summary>
public Migrator(string provider, string connectionString)
- : this(CreateProvider(provider, connectionString), Assembly.GetExecutingAssembly(), new ConsoleLogger(false))
+ : this(CreateProvider(provider, connectionString), Assembly.GetExecutingAssembly(), new Log4NetLogger())
{ }
public Migrator(TransformationProvider provider, Assembly migrationAssembly, ILogger logger)
@@ -77,13 +77,18 @@ _provider = provider;
_logger = logger;
_provider.Logger = _logger;
-
+
if (migrationAssembly == null)
+ {
+ _logger.Exception("Migration assembly not provided.", new ArgumentNullException("migrationAssembly"));
throw new ArgumentNullException("migrationAssembly");
+ }
if (provider == null)
throw new ArgumentNullException("provider");
+ _logger.Log("Performing migrations for {0}", migrationAssembly.FullName);
+
// add all providers to the "all providers" list
if (this._additionalProviders != null)
{
|
@@ -68,6 +68,7 @@ <Compile Include="IrreversibleMigrationException.cs" />
<Compile Include="Loggers\ConsoleLogger.cs" />
<Compile Include="Loggers\ILogger.cs" />
+ <Compile Include="Loggers\Log4NetLogger.cs" />
<Compile Include="Loggers\NullLogger.cs" />
<Compile Include="Migration.cs" />
<Compile Include="MigrationAttribute.cs" />
|
@@ -22,11 +22,11 @@ throw new ArgumentNullException("ConnectionString", "No config file");
_provider = new PostgreSQLTransformationProvider(constr);
- _provider.Logger = new ConsoleLogger(true);
+ _provider.Logger = new Log4NetLogger();
_provider.BeginTransaction();
-
+
_provider.AddTable("Test2",
- new Column("Id", typeof(int), ColumnProperties.PrimaryKeyWithIdentity),
+ new Column("Id", typeof(int), ColumnProperties.PrimaryKeyWithIdentity),
new Column("TestId", typeof(int))
);
}
|
Loading...