private static EFTracingConnection CreateTracingConnection(string connectionString, string providerInvariantName) { // based on the example at http://jkowalski.com/2010/04/23/logging-sql-statements-in-entity-frameworkcode-first/ string wrapperConnectionString = String.Format(@"wrappedProvider={0};{1}", providerInvariantName, connectionString); EFTracingConnection connection = new DbTracingConnection { ConnectionString = wrapperConnectionString }; // set up an event which will be raised whenever command has finished executing connection.CommandFinished += (sender, e) => { try { LogEntryData.LogEntryAsync("SQL sucess:" + e.ToTraceString(), LogSeverity.Tracing, LogCategory.DataAccess); } catch (Exception ex) { } }; connection.CommandFailed += (sender, e) => { try { LogEntryData.LogEntryAsync("SQL failed:" + e.ToTraceString(), LogSeverity.Tracing, LogCategory.DataAccess); } catch (Exception ex) { } }; return connection; }
private static EFTracingConnection CreateTracingConnection(string connectionString, string providerInvariantName) { // based on the example at http://jkowalski.com/2010/04/23/logging-sql-statements-in-entity-frameworkcode-first/ string wrapperConnectionString = String.Format(@"wrappedProvider={0};{1}", providerInvariantName, connectionString); EFTracingConnection connection = new DbTracingConnection { ConnectionString = wrapperConnectionString }; // set up an event which will be raised whenever command has finished executing connection.CommandFinished += (sender, e) => { try { LogEntryData.LogEntryAsync("SQL sucess:" + e.ToTraceString(), LogSeverity.Tracing, LogCategory.DataAccess); } catch (Exception ex) { } }; connection.CommandFailed += (sender, e) => { try { LogEntryData.LogEntryAsync("SQL failed:" + e.ToTraceString(), LogSeverity.Tracing, LogCategory.DataAccess); } catch (Exception ex) { } }; return(connection); }