Пример #1
0
 /// <summary>
 /// Create an <see cref="ILoggerProvider"/> for Google Stackdriver Logging.
 /// </summary>
 /// <param name="projectId">Optional if running on Google App Engine or Google Compute Engine.
 ///     The Google Cloud Platform project ID. If unspecified and running on GAE or GCE the project ID will be
 ///     detected from the platform.</param>
 /// <param name="options">Optional, options for the logger.</param>
 /// <param name="client">Optional, logging client.</param>
 public static GoogleLoggerProvider Create(string projectId      = null,
                                           LoggerOptions options = null, LoggingServiceV2Client client = null)
 {
     options   = options ?? LoggerOptions.Create();
     projectId = Project.GetAndCheckProjectId(projectId, options.MonitoredResource);
     return(Create(LogTarget.ForProject(projectId), options, client));
 }
 /// <summary>
 /// Adds a <see cref="GoogleLoggerProvider"/> for <see cref="GoogleLogger"/>s.
 /// </summary>
 /// <param name="factory">The logger factory. Cannot be null.</param>
 /// <param name="projectId">Optional if running on Google App Engine or Google Compute Engine.
 ///     The Google Cloud Platform project ID. If unspecified and running on GAE or GCE the project ID will be
 ///     detected from the platform.</param>
 /// <param name="options">Optional, options for the logger.</param>
 /// <param name="client">Optional, logging client.</param>
 public static ILoggerFactory AddGoogle(this ILoggerFactory factory, string projectId = null,
                                        LoggerOptions options = null, LoggingServiceV2Client client = null)
 {
     options   = options ?? LoggerOptions.Create();
     projectId = Project.GetAndCheckProjectId(projectId, options.MonitoredResource);
     return(factory.AddGoogle(LogTarget.ForProject(projectId), options, client));
 }
Пример #3
0
 /// <summary>
 /// Adds a <see cref="GoogleLoggerProvider"/> for <see cref="GoogleLogger"/>s.
 /// </summary>
 /// <param name="factory">The logger factory. Must not be null.</param>
 /// <param name="serviceProvider">The service provider to resolve additional services from.</param>
 /// <param name="projectId">Optional if running on Google App Engine or Google Compute Engine.
 ///     The Google Cloud Platform project ID. If unspecified and running on GAE or GCE the project ID will be
 ///     detected from the platform.</param>
 /// <param name="options">Optional, options for the logger.</param>
 /// <param name="client">Optional, logging client.</param>
 public static ILoggerFactory AddGoogle(this ILoggerFactory factory, IServiceProvider serviceProvider, string projectId = null,
                                        LoggerOptions options = null, LoggingServiceV2Client client = null)
 {
     GaxPreconditions.CheckNotNull(factory, nameof(factory));
     options   = options ?? LoggerOptions.Create();
     projectId = Project.GetAndCheckProjectId(projectId, options.MonitoredResource);
     return(factory.AddGoogle(LogTarget.ForProject(projectId), serviceProvider, options, client));
 }
Пример #4
0
        /// <summary>
        /// Registers the startup filter configuration action.
        /// </summary>
        /// <param name="next">A callback to the next startup filter configuration.</param>
        /// <returns>A callback of the startup filter configuration.</returns>
        public Action <IApplicationBuilder> Configure(Action <IApplicationBuilder> next)
        {
            return(app =>
            {
                var loggerFactory = app.ApplicationServices.GetServiceCheckNotNull <ILoggerFactory>();
                loggerFactory.AddGoogle(app.ApplicationServices, _projectId, LoggerOptions.Create(monitoredResource: _monitoredResource));
                app.UseGoogleExceptionLogging();
                app.UseGoogleTrace();

                next(app);
            });
        }
Пример #5
0
        /// <summary>
        /// Create an <see cref="ILoggerProvider"/> for Google Stackdriver Logging.
        /// </summary>
        /// <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 GoogleLoggerProvider Create(LogTarget logTarget,
                                                  LoggerOptions options = null, LoggingServiceV2Client client = null)
        {
            // Check params and set defaults if unset.
            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);

            return(new GoogleLoggerProvider(consumer, logTarget, options));
        }
        /// <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);
        }