/// <summary>
 /// Adds a <see cref="GoogleLoggerProvider"/> for <see cref="GoogleLogger"/>s.
 /// </summary>
 /// <param name="factory">The logger factory. Cannot be null.</param>
 /// <param name="logTarget">Where to log to. Cannot be null.</param>
 /// <param name="options">Optional, options for the logger.</param>
 /// <param name="client">Optional, logging client.</param>
 public static ILoggerFactory AddGoogle(this ILoggerFactory factory, LogTarget logTarget,
                                        LoggerOptions options = null, LoggingServiceV2Client client = null)
 {
     GaxPreconditions.CheckNotNull(factory, nameof(factory));
     factory.AddProvider(GoogleLoggerProvider.Create(logTarget, options, client));
     return(factory);
 }
        /// <summary>
        /// Adds a <see cref="GoogleLoggerProvider"/> for <see cref="GoogleLogger"/>s.
        /// </summary>
        /// <param name="factory">The logger factory. Cannot be null.</param>
        /// <param name="logTarget">Where to log to. Cannot be null.</param>
        /// <param name="options">Optional, options for the logger.</param>
        /// <param name="client">Optional, logging client.</param>
        public static ILoggerFactory AddGoogle(this ILoggerFactory factory, LogTarget logTarget,
                                               LoggerOptions options = null, LoggingServiceV2Client client = null)
        {
            // Check params and set defaults if unset.
            GaxPreconditions.CheckNotNull(factory, nameof(factory));
            GaxPreconditions.CheckNotNull(logTarget, nameof(logTarget));
            client  = client ?? LoggingServiceV2Client.Create();
            options = options ?? LoggerOptions.Create();

            // Get the proper consumer from the options and add a logger provider.
            IConsumer <LogEntry> consumer = LogConsumer.Create(client, options.BufferOptions, options.RetryOptions);
            GoogleLoggerProvider provider = new GoogleLoggerProvider(consumer, logTarget, options);

            factory.AddProvider(provider);
            return(factory);
        }
        /// <summary>
        /// Adds a <see cref="GoogleLoggerProvider"/> for <see cref="GoogleLogger"/>s.
        /// </summary>
        /// <param name="factory">The logger factory. Cannot be null.</param>
        /// <param name="logTo">Where to log to. Cannot be null. Cannot be null.</param>
        /// <param name="options">Optional, options for the logger.</param>
        /// <param name="client">Optional, logging client.</param>
        public static ILoggerFactory AddGoogle(this ILoggerFactory factory, LogTo logTo,
                                               LoggerOptions options = null, LoggingServiceV2Client client = null)
        {
            // Check params and set defaults if unset.
            GaxPreconditions.CheckNotNull(factory, nameof(factory));
            GaxPreconditions.CheckNotNull(logTo, nameof(logTo));
            client  = client ?? LoggingServiceV2Client.Create();
            options = options ?? LoggerOptions.Create();

            // Get the proper consumer from the options and add a logger provider.
            GrpcLogConsumer      grpcConsumer = new GrpcLogConsumer(client);
            IConsumer <LogEntry> consumer     = ConsumerFactory <LogEntry> .GetConsumer(
                grpcConsumer, LogEntrySizer.Instance, options.BufferOptions);

            GoogleLoggerProvider provider = new GoogleLoggerProvider(consumer, logTo, options);

            factory.AddProvider(provider);
            return(factory);
        }