Reputation: 561
How can I log when the SqlAzureExecutionStrategy retries an Entity Framework operation? When using the transient fault handling logic with regular SqlConnection calls, a Retrying event is exposed. Is there something similar when using the SqlAzureExecutionStrategy with Entity Framework 6? If not, what are some other options?
Upvotes: 4
Views: 1405
Reputation: 99
You can create a custom ExecutionStrategy which inherits from the SqlAzureExecutionStrategy, and override the ShouldRetryOn method:
public class LoggedSqlAzureExecutionStrategy : SqlAzureExecutionStrategy
{
protected override bool ShouldRetryOn(Exception exception)
{
var shouldRetry = base.ShouldRetryOn(exception);
if (shouldRetry)
{
// log exception
}
return shouldRetry;
}
}
Upvotes: 0
Reputation: 1230
There is a very good article on this topic explaining all the steps for logging Azure SQL database with ASP.NET MVC and EntityFramework:. Hope this helps. Here is the link to it: asp.net/mvc/overview/getting-started/… – ACS yesterday
As stated in the comment by ACS, this guide discusses connection resiliency and command interception for Entity Framework.This document discusses how to built the retry logic in EF6 and how to create a logging interface and class to log the events.
In addition to the previous link, there is a topic which discusses connection resiliency/retry logic in EF6 and its limitations.
Hope this helps!
Upvotes: 2