I'm using EntityFramework code first with migrations. From the package manager console, I'm running "update-database". This executes Configuration.Seed(context) which I have overridden.
protected override void Seed(WebContext context)
{
Console.WriteLine("Console Test");
Debug.WriteLine("Debug Test");
Trace.WriteLine("Trace Test");
}
Where can I find that output?
Better yet, How do I output back to the package manager window?
Thx, Dan
Dirty workaround extending George's answer.
Sorry, but the quick answer is basically nowhere.
To be precise at least not in the package manager console.
You can see the output of the
Debug...
andTrace...
methods if you attach another Visual Studio to debug the Visual Studio instance which is running theupdate-database
command. Then in the debuggin VS you can see the output in the Output Window.You can see the output of the
Console...
methods if you run the migrations with themigrate.exe
command line tool which comes with EF:I have here also bad news, after a quick "reflectoring": with the current implementation of the EF migrations it's not supported to display custom information during execution of the
update-database
(or any other command).Running a SQL print command will write to the Package Manager Console. Here is a helper method that I use:
A quick hack I use to be able to quickly find a value in my Seed method is simply to throw an exception with a value I care about, e.g.
This errors out the Seed, but my exception/value appears in my package manager console.
My needs were similar to yours so I figured I'd document them here in case they could help someone else out. My goal was to display all of the output from the migrations including all of the sql run as part of the Seed method. As a side effect of this solution, you will also be able to see any Debug.Write message in your code.
First create a DebugMigrationsLogger that will write all migration output to Debug.WriteLine (thanks to http://whiteknight.github.io/2013/01/26/efcodeonlymigrations.html):
Next make sure you have a subclass of DbMigrationsConfiguration for your DbContext:
Next you run your migrations as an on-demand unit test so your test runner can capture the output. My unit test looks something like this:
Lastly, set the Database.Log in your DbContext constructor:
Now whenever you run the MigrateDb_Test() you will see all the output, it has made debugging migrations so much easier for me!