/// <inheritdoc /> /// <summary> /// Construct a sink inserting into InfluxDB with the specified details. /// </summary> /// <param name="connectionInfo">Connection information used to construct InfluxDB client.</param> /// <param name="source">Measurement name in the InfluxDB database.</param> /// <param name="batchSizeLimit">The maximum number of events to post in a single batch.</param> /// <param name="period">The time to wait between checking for event batches.</param> /// <param name="formatProvider"></param> public InfluxDBv2Sink( InfluxDBv2ConnectionInfo connectionInfo, string source, int batchSizeLimit, TimeSpan period, IFormatProvider formatProvider ) : base(batchSizeLimit, period) { _connectionInfo = connectionInfo ?? throw new ArgumentNullException(nameof(connectionInfo)); _source = source; _influxDbClient = CreateInfluxDbClient(); _formatProvider = formatProvider; }
/// <summary> /// Writes log events to InfluxDB. /// </summary> private static LoggerConfiguration InfluxDBv2( this LoggerSinkConfiguration loggerConfiguration, string source, string address, string bucket, string username, string password, string token, string organization = InfluxDBv2Defaults.DefaultOrganizationName, LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, int batchPostingLimit = InfluxDBv2Sink.DefaultBatchPostingLimit, TimeSpan?period = null, IFormatProvider formatProvider = null) { // Define connection type var connectionType = AuthenticationScheme.Session; if (!string.IsNullOrEmpty(token)) { connectionType = AuthenticationScheme.Token; } // Create connection info configuration var connectionInfo = new InfluxDBv2ConnectionInfo { Address = address, Bucket = bucket, Organization = organization, AuthenticationType = connectionType, Username = username, Password = password, Token = token }; // Set the default period if it is null var defaultedPeriod = period ?? InfluxDBv2Sink.DefaultPeriod; // Register InfluxDB in Serilog return(loggerConfiguration.Sink(new InfluxDBv2Sink(connectionInfo, source, batchPostingLimit, defaultedPeriod, formatProvider), restrictedToMinimumLevel)); }