Ejemplo n.º 1
0
        private string BuildConnectionString(LogEventInfo logEvent)
        {
            if (_connectionStringCache != null)
            {
                return(_connectionStringCache);
            }

            if (_connectionString != null)
            {
                return(_connectionString.GetFormattedMessage(logEvent));
            }

            StringBuilder sb = new StringBuilder();

            sb.Append("Server=");
            sb.Append(DBHostLayout.GetFormattedMessage(logEvent));
            sb.Append(";");
            if (DBUserNameLayout == null)
            {
                sb.Append("Trusted_Connection=SSPI;");
            }
            else
            {
                sb.Append("User id=");
                sb.Append(DBUserNameLayout.GetFormattedMessage(logEvent));
                sb.Append(";Password="******";");
            }

            if (DBDatabaseLayout != null)
            {
                sb.Append("Database=");
                sb.Append(DBDatabaseLayout.GetFormattedMessage(logEvent));
            }

            _connectionStringCache = sb.ToString();

            InternalLogger.Debug("Connection string: {0}", _connectionStringCache);
            return(_connectionStringCache);
        }