/// <summary> /// Adds all layouts used by this target to the specified collection. /// </summary> /// <param name="layouts">The collection to add layouts to.</param> public override void PopulateLayouts(LayoutCollection layouts) { base.PopulateLayouts(layouts); if (DBHostLayout != null) { DBHostLayout.PopulateLayouts(layouts); } if (DBUserNameLayout != null) { DBUserNameLayout.PopulateLayouts(layouts); } if (DBDatabaseLayout != null) { DBDatabaseLayout.PopulateLayouts(layouts); } if (DBPasswordLayout != null) { DBPasswordLayout.PopulateLayouts(layouts); } if (CommandTextLayout != null) { CommandTextLayout.PopulateLayouts(layouts); } for (int i = 0; i < Parameters.Count; ++i) { if (Parameters[i].CompiledLayout != null) { Parameters[i].CompiledLayout.PopulateLayouts(layouts); } } }
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); }