I have an application that uses both Entity Framework and Dapper. I would like to provide a custom logger to log out any sql that is issued over the ado.net connection. What is the best way of doing this?
Alternately, if it's not easily possible what exactly are the difficulties?
To retrieve all columns, use the wild card * (an asterisk). The FROM clause specifies one or more tables to be queried. Use a comma and space between table names when specifying multiple tables. The WHERE clause selects only the rows in which the specified column contains the specified value.
You can view the SQL code generated for queries and change processing by using the Log property. This approach can be useful for understanding LINQ to SQL functionality and for debugging specific problems.
To retrieve data using a DataReader, create an instance of the Command object, and then create a DataReader by calling Command. ExecuteReader to retrieve rows from a data source.
Would ADO.NET Data Tracing work for you? It plugs into ETW, from which you might be able to glue your current logging system. Doesn't seem much stand-alone though.
Miniprofiler, which is written by the same team, works with both dapper and Entity Framework - although iirc the later requires a bit more work. This provides the ability for both logging and profiling of ADO.NET commands. We use it 24x7 here on stackoverflow (and the entire stack exchange network), so it works well even at scale.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With