Using the guide here, I'm trying to log the SQL generated by my MVC web application.
The guide uses the line:
context.Database.Log = Console.Write;
Which obviously doesn't work with a web application. The guide described the Log property:
The DbContext.Database.Log property can be set to a delegate for any method that takes a string.
And it's this I don't understand, delegates just confuse me. How can I use this EF6 feature?
To write your logs to a file, try this:
Using a delegate allows you to do write any function taking a string. As a very simple logging to a file, you could do the following:
In a web environment, you may wish to use Trace to log this information:
You can see more examples of using delegates on the MSDN page on Anonymous Functions.