/// <summary>
        /// Create an <see cref="ILoggerProvider"/> for Google Cloud Logging.
        /// </summary>
        public static GoogleLoggerProvider Create(IServiceProvider serviceProvider, LoggingServiceOptions options = null)
        {
            options = options ?? new LoggingServiceOptions();
            var loggingOptions = options.Options ?? LoggingOptions.Create();

            var logTarget      = options.LogTarget ?? LogTarget.ForProject(Project.GetAndCheckProjectId(null, loggingOptions.MonitoredResource));
            var serviceContext = ServiceContextUtils.CreateServiceContext(
                Project.GetServiceName(options.ServiceName, loggingOptions.MonitoredResource),
                Project.GetServiceName(options.Version, loggingOptions.MonitoredResource));
            var client = options.Client ?? LoggingServiceV2Client.Create();
            IConsumer <LogEntry> consumer = LogConsumer.Create(client, loggingOptions.BufferOptions, loggingOptions.RetryOptions);

            var provider = new GoogleLoggerProvider(consumer, logTarget, serviceContext, loggingOptions, serviceProvider);

            var writer = options.LoggerDiagnosticsOutput;

            if (writer != null)
            {
                // The log name is the ASP.NET Core log name, not the "/projects/xyz/logs/abc" log name in the resource.
                // We don't currently use this in the diagnostics, but if we ever start to do so, SampleLogName seems
                // like a reasonably clear example.
                ((GoogleLogger)provider.CreateLogger("SampleLogName")).WriteDiagnostics(writer);
            }

            return(provider);
        }
 /// <summary>
 /// Adds a <see cref="GoogleLoggerProvider"/> for <see cref="GoogleLogger"/>s.
 /// </summary>
 public static ILoggingBuilder AddGoogle(this ILoggingBuilder builder, LoggingServiceOptions options = null)
 {
     builder.Services.AddSingleton <ILoggerProvider, GoogleLoggerProvider>(sp => GoogleLoggerProvider.Create(sp, options));
     return(builder);
 }