You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
failOnError: should an exception thrown by the action stop the query execution or should it be ignored ?
execution time could be replaced by a Statistics object (connection acquisition time, query execution time, mapping execution time...).
These methods could be static:
Dapper.Listeners.AddAfterQueryExecutionListener((command,result,executionTime)=>{ Console.WriteLine($"it took {executionTime} to execute {command.CommandText}");});
namespace Dapper;publicstaticclassListeners{publicstaticboolEnabled{get;set;}// To enabled or disable listeners at runtimeinternalstaticList<(Action<DbCommand> action,bool failOnError)> BeforeExecutionListeners {get;}=[];internalstaticList<(Action<DbCommand,object,long> action,bool failOnError)> AfterExecutionListeners {get;}=[];internalstaticList<Action<DbCommand,Exception>> AfterExceptionListeners {get;}=[];publicstaticvoidAddBeforeExecutionListener(Action<DbCommand>action,boolfailOnError=false){
BeforeExecutionListeners.Add((action, failOnError));Enabled=true;}publicstaticvoidAddAfterQueryExecutionListener(Action<DbCommand,object,long>action,boolfailOnError=false){
AfterExecutionListeners.Add((action, failOnError));Enabled=true;}publicstaticvoidAddAfterExceptionListeners(Action<DbCommand,Exception>action){
AfterExceptionListeners.Add(action);Enabled=true;}}
With named listeners, RemoveListener methods could also be implemented.
SqlMapperQuery and Execute method would check Listeners.Enabled value and, if it is true, call the listeners before and after query executions.
It would be useful for profiling and exception handling, in my case I need to expose the execution time of some queries to Prometheus.
The text was updated successfully, but these errors were encountered:
Dapper could offer several
AddListener
methods: before query execution, after query execution, after exception.failOnError
: should an exception thrown by the action stop the query execution or should it be ignored ?execution time could be replaced by a
Statistics
object (connection acquisition time, query execution time, mapping execution time...).These methods could be static:
With named listeners,
RemoveListener
methods could also be implemented.SqlMapper
Query
andExecute
method would checkListeners.Enabled
value and, if it is true, call the listeners before and after query executions.It would be useful for profiling and exception handling, in my case I need to expose the execution time of some queries to Prometheus.
The text was updated successfully, but these errors were encountered: