Ejemplo n.º 1
0
        /// <summary>
        /// Writes log events to Google Cloud Platform Stackdriver Logging.
        /// </summary>
        /// <param name="loggerConfiguration">Logger sink configuration.</param>
        /// <param name="sinkOptions">Google Cloud Logging sink options.</param>
        /// <param name="batchSizeLimit">The maximum number of events to include in a single batch. The defailt is 100.</param>
        /// <param name="period">The time to wait between checking for event batches. The default is five seconds.</param>
        /// <param name="queueLimit">Maximum number of events in the queue. If not specified, uses an unbounded queue.</param>
        /// <param name="outputTemplate">A message template describing the format used to write to the sink.</param>
        /// <param name="restrictedToMinimumLevel">The minimum level for events passed through the sink. Ignored when <paramref name="levelSwitch"/> is specified.</param>
        /// <param name="levelSwitch">A switch allowing the pass-through minimum level to be changed at runtime.</param>
        /// <returns>Configuration object allowing method chaining.</returns>
        public static LoggerConfiguration GoogleCloudLogging(
            this LoggerSinkConfiguration loggerConfiguration,
            GoogleCloudLoggingSinkOptions sinkOptions,
            int?batchSizeLimit    = null,
            TimeSpan?period       = null,
            int?queueLimit        = null,
            string outputTemplate = null,
            LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
            LoggingLevelSwitch levelSwitch         = null)
        {
            var messageTemplateTextFormatter = String.IsNullOrWhiteSpace(outputTemplate) ? null : new MessageTemplateTextFormatter(outputTemplate, null);

            var sink = new GoogleCloudLoggingSink(
                sinkOptions,
                messageTemplateTextFormatter
                );

            var batchingOptions = new PeriodicBatchingSinkOptions
            {
                BatchSizeLimit = batchSizeLimit ?? 100,
                Period         = period ?? TimeSpan.FromSeconds(5),
                QueueLimit     = queueLimit
            };

            var batchingSink = new PeriodicBatchingSink(sink, batchingOptions);

            return(loggerConfiguration.Sink(batchingSink, restrictedToMinimumLevel, levelSwitch));
        }
        public static LoggerConfiguration GoogleCloudLogging(this LoggerSinkConfiguration loggerConfiguration, GoogleCloudLoggingSinkOptions sinkOptions, int?batchSizeLimit = null, TimeSpan?period = null, string outputTemplate = null)
        {
            var messageTemplateTextFormatter = String.IsNullOrWhiteSpace(outputTemplate) ? null : new MessageTemplateTextFormatter(outputTemplate, null);

            var sink = new GoogleCloudLoggingSink(
                sinkOptions,
                messageTemplateTextFormatter,
                batchSizeLimit ?? 100,
                period ?? TimeSpan.FromSeconds(5)
                );

            return(loggerConfiguration.Sink(sink));
        }