@@ -41,13 +41,15 @@ public static string GetUniqueDBName(string namePrefix)
4141 /// </summary>
4242 /// <param name="connection">The connection. This must be opened.</param>
4343 /// <param name="commandText">The scalar T-SQL command.</param>
44+ /// <param name="logger">The method to call for logging output</param>
4445 /// <param name="catchException">Optional exception handling. Pass back 'true' to handle the
4546 /// exception, 'false' to throw. If Null is passed in then all exceptions are thrown.</param>
4647 /// <param name="message">Optional message to write when this query is executed. Defaults to writing the query commandText</param>
4748 /// <returns>The number of rows affected</returns>
4849 public static int ExecuteNonQuery (
4950 IDbConnection connection ,
5051 string commandText ,
52+ Action < string > logger ,
5153 Predicate < Exception > catchException = null ,
5254 string message = null )
5355 {
@@ -69,7 +71,7 @@ public static int ExecuteNonQuery(
6971 cmd . CommandText = commandText ;
7072 cmd . CommandType = CommandType . Text ;
7173 cmd . CommandTimeout = 60 ; // Increase from default 30s to prevent timeouts while connecting to Azure SQL DB
72- Console . WriteLine ( message ) ;
74+ logger . Invoke ( message ) ;
7375 return cmd . ExecuteNonQuery ( ) ;
7476 }
7577 catch ( Exception ex )
@@ -89,12 +91,14 @@ public static int ExecuteNonQuery(
8991 /// </summary>
9092 /// <param name="connection">The connection. This must be opened.</param>
9193 /// <param name="commandText">The scalar T-SQL command.</param>
94+ /// <param name="logger">The method to call for logging output</param>
9295 /// <param name="catchException">Optional exception handling. Pass back 'true' to handle the
9396 /// exception, 'false' to throw. If Null is passed in then all exceptions are thrown.</param>
9497 /// <returns>The scalar result</returns>
9598 public static object ExecuteScalar (
9699 IDbConnection connection ,
97100 string commandText ,
101+ Action < string > logger ,
98102 Predicate < Exception > catchException = null )
99103 {
100104 if ( connection == null )
@@ -112,7 +116,7 @@ public static object ExecuteScalar(
112116 {
113117 cmd . CommandText = commandText ;
114118 cmd . CommandType = CommandType . Text ;
115- Console . WriteLine ( $ "Executing scalar { commandText } ") ;
119+ logger . Invoke ( $ "Executing scalar { commandText } ") ;
116120 return cmd . ExecuteScalar ( ) ;
117121 }
118122 catch ( Exception ex )
@@ -132,10 +136,11 @@ public static object ExecuteScalar(
132136 /// Retries the specified action, waiting for the specified duration in between each attempt
133137 /// </summary>
134138 /// <param name="action">The action to run</param>
139+ /// <param name="logger">The method to call for logging output</param>
135140 /// <param name="retryCount">The max number of retries to attempt</param>
136141 /// <param name="waitDurationMs">The duration in milliseconds between each attempt</param>
137142 /// <exception cref="AggregateException">Aggregate of all exceptions thrown if all retries failed</exception>
138- public static void Retry ( Action action , int retryCount = 3 , int waitDurationMs = 10000 )
143+ public static void Retry ( Action action , Action < string > logger , int retryCount = 3 , int waitDurationMs = 10000 )
139144 {
140145 var exceptions = new List < Exception > ( ) ;
141146 while ( true )
@@ -153,7 +158,7 @@ public static void Retry(Action action, int retryCount = 3, int waitDurationMs =
153158 {
154159 throw new AggregateException ( $ "Action failed all retries", exceptions ) ;
155160 }
156- Console . WriteLine ( $ "Error running action, retrying after { waitDurationMs } ms. { retryCount } retries left. { ex } ") ;
161+ logger . Invoke ( $ "Error running action, retrying after { waitDurationMs } ms. { retryCount } retries left. { ex } ") ;
157162 Thread . Sleep ( waitDurationMs ) ;
158163 }
159164 }
0 commit comments