How do I safely call an async method from EF's non-async SaveChanges?
<p>I'm using ASP.NET Core, and EF Core which has <code>SaveChanges</code> and <code>SaveChangesAsync</code>.</p>

<p>Before saving to the database, in my <code>DbContext</code>, I perform some auditing/logging:</p>

<pre><code>public async Task LogAndAuditAsync() {
    // do async stuff
}

public override int SaveChanges {
    /*await*/ LogAndAuditAsync();      // what do I do here???
    return base.SaveChanges();
}

public override async Task&lt;int&gt; SaveChangesAsync {
    await LogAndAuditAsync();
    return await base.SaveChanges();
}
</code></pre>

<p>The problem is the synchronous <code>SaveChanges()</code>.</p>

<p>I always do "async all the way down", but here that isn't possible. I could redesign to have <code>LogAndAudit()</code> and <code>LogAndAuditAsync()</code> but that is not DRY and I'll need to change a dozen other major pieces of code which don't belong to me.</p>

<p>There are lots of other questions about this topic, and all are general and complex and full of debate. <em>I need to know the safest approach in this specific case</em>.</p>

<p>So, in <code>SaveChanges()</code>, how do I safely and synchronously call an async method, without deadlocks?</p>