How to do a time logger class wrapper in C#
<p>I have a lot (around a thousand) of <code>FluentMigrator</code> <code>Migration</code> classes that started timing out on our build server.</p>

<p>For those who haven't worked with <code>FluentMigrator</code> - Migrations are working in such way that all your migrations inherit from <code>Migration</code> class that has <code>Up()</code> and <code>Down()</code> methods that run SQL scripts for db migrations - simple and easy. </p>

<p>Now being lazy I have introduced a <code>LoggingMigration</code> class that logs the time when migration starts running (and simply replaced <code>: Migration</code> to <code>: LoggingMigration</code> in VS for that project).</p>

<pre><code>public class LoggingMigration : Migration
{
    public DateTime StartTime { get; private set; }

    public LoggingMigration()
    {
        this.StartTime = DateTime.Now;
        Console.WriteLine("Start {0} - TIME: {1:yyyy-MM-dd HH:mm:ss.fff}", this.GetType().Name, StartTime);
    }

    public override void Up()
    {
    }

    public override void Down()
    {
    }
}
</code></pre>

<p>I want to also do a time on how long migration was running to make it easier to see which migrations take long.</p>

<p>I was thinking of using destructor like:</p>

<pre><code>    ~LoggingMigration()
    {
        Console.WriteLine("End(?) {0} - TIME: {1}", this.GetType().Name, DateTime.Now.Subtract(StartTime));
    }
</code></pre>

<p>but thing is just to <a href="https://stackoverflow.com/questions/16032451/get-datetime-now-with-milliseconds-precision#answer-16032517">volatile and unpredictable</a> </p>

<p><strong>How to add mechanism that would run after <code>Up()</code> method in child class finishes?
Or some other way that does the job?</strong></p>