<p>I have written a few MSBuild custom tasks that work well and are use in our CruiseControl.NET build process.</p>

<p>I am modifying one, and wish to unit test it by calling the Task's Execute() method. </p>

<p>However, if it encounters a line containing </p>

<pre><code>Log.LogMessage("some message here");
</code></pre>

<p>it throws an InvalidOperationException:</p>

<p><em>Task attempted to log before it was initialized. Message was...</em></p>

<p>Any suggestions? (In the past I have mostly unit-tested Internal static methods on my custom tasks to avoid such problems.)</p>

If you have implemented the interface ITask you will have to initialise the Log class yourself.
Otherwise you should just inherit from
Task
in Microsoft.Build.Utilities.dll
That implements
ITask
and does a lot of the leg work for you.
Here is the reference page for building a custom task, it explains quite a lot of it.
Building a custom MSBuild task reference
Also worth a look is
How to debug a custom MSBuild task
Other then that could you post the MSBuild XML you are using for calling your custom task.
The code itself would obviously be the most help :-)