コード例 #1
0
    private void ConnectionBeforeOpen(object sender, BeforeOpenDbConnectionEventArgs e)
    {
        var csb = new DbConnectionStringBuilder {
            ConnectionString = e.ConnectionString
        };

        if (csb.ContainsKey("Password"))
        {
            csb["Password"] = "******";
        }

        Log.Trace("Opening connection {0}...", csb.ConnectionString);

        _beforeOpen = e;
    }
コード例 #2
0
    private void ConnectionAfterOpen(object sender, AfterOpenDbConnectionEventArgs e)
    {
        var duration = e.Timestamp - _beforeOpen.Timestamp;

        if (e.Exception != null)
        {
            Log.Write(LogLevel.Error, "Opening connection finished in {0} seconds. Exception:\r\n{1}", StopwatchTimeSpan.ToString(duration, 3),
                      e.Exception.ToLogString());
        }
        else
        {
            Log.Trace("Opening connection finished in {0} seconds.", StopwatchTimeSpan.ToString(duration, 3));
        }

        _beforeOpen = null;
    }