Exemple #1
0
 /// <summary>
 /// 封装成DbConnection
 /// </summary>
 /// <param name="connectionString">连接字符串</param>
 /// <param name="providerInvariantName">wappername</param>
 /// <returns>wrapperConnectionString</returns>
 private static EFTracingConnection CreateTracingConnection(
     string connectionString,
     string providerInvariantName)
 {
     string wrapperConnectionString = string.Format(
         @"wrappedProvider={0};{1}",
         providerInvariantName,
         connectionString);
     var connection = new EFTracingConnection { ConnectionString = wrapperConnectionString };
     return connection;
 }
 public EFTracingConnection CreateTracingConnection()
 {
     var tracingConnection = new EFTracingConnection { ConnectionString = tracingConnectionString };
     tracingConnection.CommandFinished += (s, e) => {
         if(LogToConsole)
             Console.WriteLine(e.ToTraceString());
         if(!string.IsNullOrEmpty(LogFileName))
             File.AppendAllText(LogFileName, e.ToTraceString() + Environment.NewLine + Environment.NewLine);
         //try {
         //    if(LogToConsole)
         //        Console.WriteLine(e.ToTraceString());
         //    if(!string.IsNullOrEmpty(LogFileName))
         //        File.AppendAllText(LogFileName, e.ToTraceString() + Environment.NewLine + Environment.NewLine);
         //}
         //catch {
         //    // catch all exceptions so that we don't pass logging-related failures to user code
         //}
     };
     return tracingConnection;
 }
 private static DbConnection CreateConnection(String connectionString, String providerInvariantName)
 {
     var wrapperConnectionString = String.Format(@"wrappedProvider={0};{1}", providerInvariantName, connectionString);
        var connection = new EFTracingConnection { ConnectionString = wrapperConnectionString };
        return (connection);
 }
Exemple #4
0
        /// <summary>
        /// CreateTracingConnection with providerInvariantName
        /// </summary>
        /// <param name="connString">
        /// Connection String 
        /// </param>
        /// <param name="providerInvariantName">
        /// provider Invariant Name
        /// </param>
        /// <returns>
        /// EFTracingConnection obj
        /// </returns>
        private static EFTracingConnection CreateTracingConnection(string connString, 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, connString);

            var connection = new EFTracingConnection {ConnectionString = wrapperConnectionString};

            return connection;
        }