How to log Entity Framework 4.3 Beta 1 migrations
-
Sunday, January 15, 2012 9:40 PM
I am just trying it out the new Code First migrations version.
I am going the "magic" track most of the time, so I've found it really useful in previous version to add some logging such as:
Where did this option go in the latest release?new DbMigrator(.....); dbMigrator.Update(MigratorEventHandler); ... private void MigratorEventHandler(object sender, DbMigrationEventArgs e) { _log.Info(string.Format("Migration event {0}", e.ToString())); }
All Replies
-
Monday, January 16, 2012 7:08 PM
Logging can be achieved by using the MigratorLoggingDecorator class. For examplevar dbMigrator = new MigratorLoggingDecorator(new DbMigrator(...), new MyLogger(_log)); dbMigrator.Update(); ... class MyLogger : MigrationsLogger { ... public override void Info(string message) { _log.Info(string.Format("Migration event INFO: {0}", message); } ... }
Brice Lambson- Proposed As Answer by Brice Lambson - MSFTMicrosoft Employee Monday, January 16, 2012 9:47 PM
-
Monday, January 16, 2012 9:30 PM
Thanks, cool enough. Almost at the same time as you replied, I just figured the same, using reflector :-). Is there a more detailed list of API changes than what is present at the "What changed" section of the release page http://blogs.msdn.com/b/adonet/archive/2012/01/12/ef-4-3-beta-1-released.aspx?
-
Monday, January 16, 2012 9:46 PM
The API you were using was actually changed back in Code First Migrations Alpha 2. You may want to check all of the What's Changed sections in the release posts:
- Code First Migrations: Alpha 2 Released
- Code First Migrations: Alpha 3 Released
- Code First Migrations: Beta 1 Released
Brice Lambson

