private void Init() { _standardColumnNames = new HashSet <string>(StringComparer.OrdinalIgnoreCase); foreach (var stdCol in _opt.ColumnOptions.Store) { var col = _opt.ColumnOptions.GetStandardColumnOptions(stdCol); _standardColumnNames.Add(col.ColumnName); } _additionalColumnNames = new HashSet <string>(StringComparer.OrdinalIgnoreCase); if (_opt.ColumnOptions.AdditionalColumns != null) { foreach (var col in _opt.ColumnOptions.AdditionalColumns) { _additionalColumnNames.Add(col.ColumnName); } } if (_opt.ColumnOptions.Store.Contains(StandardColumn.LogEvent)) { _jsonLogEventFormatter = new JsonLogEventFormatter(this); } _eventTable = CreateDataTable(); if (_tableCreator != null && _opt.AutoCreateSqlTable) { _tableCreator.CreateTable(_opt, _eventTable); } }
/// <summary> /// /// </summary> /// <param name="connectionString"></param> /// <param name="tableName"></param> /// <param name="schemaName"></param> /// <param name="columnOptions"></param> /// <param name="formatProvider"></param> /// <param name="autoCreateSqlTable"></param> public DbSinkTraits(ProviderType type, Func <IDbConnection> func, string tableName, string schemaName, ColumnOptions columnOptions, IFormatProvider formatProvider, bool autoCreateSqlTable) { //if (string.IsNullOrWhiteSpace(connectionString)) // throw new ArgumentNullException(nameof(connectionString)); if (string.IsNullOrWhiteSpace(tableName)) { throw new ArgumentNullException(nameof(tableName)); } _type = type; //this.connectionString = connectionString; this.tableName = tableName; this.schemaName = schemaName; this.columnOptions = columnOptions ?? new ColumnOptions(); this.formatProvider = formatProvider; standardColumnNames = new HashSet <string>(StringComparer.OrdinalIgnoreCase); foreach (var stdCol in this.columnOptions.Store) { var col = this.columnOptions.GetStandardColumnOptions(stdCol); standardColumnNames.Add(col.ColumnName); } additionalColumnNames = new HashSet <string>(StringComparer.OrdinalIgnoreCase); if (this.columnOptions.AdditionalColumns != null) { foreach (var col in this.columnOptions.AdditionalColumns) { additionalColumnNames.Add(col.ColumnName); } } if (this.columnOptions.Store.Contains(StandardColumn.LogEvent)) { jsonLogEventFormatter = new JsonLogEventFormatter(null); } eventTable = CreateDataTable(); if (autoCreateSqlTable) { try { SqlTableCreator tableCreator = new SqlTableCreator(type, func, this.schemaName, this.tableName, eventTable, this.columnOptions); tableCreator.CreateTable(); // return code ignored, 0 = failure? } catch (Exception ex) { Console.WriteLine($"Exception creating table {tableName}:\n{ex}"); } } }