internal GoogleLogger(
            IConsumer <LogEntry> consumer, LogTarget logTarget, Struct serviceContext, LoggingOptions loggerOptions,
            string logName, IClock clock = null, IServiceProvider serviceProvider = null)
#pragma warning disable CS0618 // Type or member is obsolete
            : this(consumer, logTarget, serviceContext, loggerOptions, logName, null, null, clock, serviceProvider)
#pragma warning restore CS0618 // Type or member is obsolete
        {
        }
Example #2
0
 /// <summary>
 /// Creates a new <see cref="EventTarget"/> instance that will report to the Stackdriver Logging API.
 /// The events are then automatically propigated to the Stackdriver Error Logging API from the
 /// Stackdriver Logging API.
 /// </summary>
 /// <remarks>
 /// For more information see "Formatting Log Error Messages"
 /// (https://cloud.google.com/error-reporting/docs/formatting-error-messages).
 /// </remarks>
 /// <param name="logTarget">Where to log to, such as a project or organization. Cannot be null.</param>
 /// <param name="logName">The log name.  Cannot be null.</param>
 /// <param name="loggingClient">The logging client.</param>
 /// <param name="monitoredResource">Optional, the monitored resource.  The monitored resource will
 ///     be automatically detected if it is not set and will default to the global resource if the detection fails.
 ///     See: https://cloud.google.com/logging/docs/api/v2/resource-list </param>
 public static EventTarget ForLogging(LogTarget logTarget, string logName  = LogNameDefault,
                                      LoggingServiceV2Client loggingClient = null, MonitoredResource monitoredResource = null)
 {
     return(new EventTarget
     {
         Kind = EventTargetKind.Logging,
         LoggingClient = loggingClient ?? LoggingServiceV2Client.Create(),
         LogTarget = GaxPreconditions.CheckNotNull(logTarget, nameof(logTarget)),
         LogName = GaxPreconditions.CheckNotNullOrEmpty(logName, nameof(logName)),
         MonitoredResource = monitoredResource ?? MonitoredResourceBuilder.FromPlatform(),
     });
 }
        /// <summary>
        /// Create an <see cref="ILoggerProvider"/> for Google Cloud Logging.
        /// </summary>
        /// <param name="logTarget">Where to log to. Must not be null.</param>
        /// <param name="serviceProvider">Optional, the service provider to resolve additional services from. May be null,
        /// in which case additional services (such as custom labels) will not be used.</param>
        /// <param name="options">Optional, options for the logger.</param>
        /// <param name="client">Optional, logging client.</param>
        public static GoogleLoggerProvider Create(LogTarget logTarget, IServiceProvider serviceProvider,
                                                  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, serviceProvider));
        }
        /// <summary>
        /// <see cref="ILoggerProvider"/> for Google Cloud Logging.
        /// </summary>
        /// <param name="consumer">The consumer to push logs to. Must not be null.</param>
        /// <param name="logTarget">Where to log to. Must not be null.</param>
        /// <param name="loggerOptions">The logger options. Must not be null.</param>
        /// <param name="serviceProvider">The service provider to resolve additional services from.</param>
        internal GoogleLoggerProvider(IConsumer <LogEntry> consumer, LogTarget logTarget, LoggerOptions loggerOptions, IServiceProvider serviceProvider)
        {
            _consumer        = GaxPreconditions.CheckNotNull(consumer, nameof(consumer));
            _logTarget       = GaxPreconditions.CheckNotNull(logTarget, nameof(logTarget));
            _loggerOptions   = GaxPreconditions.CheckNotNull(loggerOptions, nameof(loggerOptions));
            _serviceProvider = serviceProvider;

            var writer = loggerOptions.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)CreateLogger("SampleLogName")).WriteDiagnostics(writer);
            }
        }
Example #5
0
 internal GoogleLogger(IConsumer <LogEntry> consumer, LogTarget logTarget, LoggerOptions loggerOptions, string logName,
                       Action <IServiceProvider, Dictionary <string, string> > obsoleteLabelsGetter,
                       Action <IServiceProvider, LogEntry, TraceTarget> obsoleteTraceContextGetter,
                       IClock clock = null, IServiceProvider serviceProvider = null)
 {
     _logTarget   = GaxPreconditions.CheckNotNull(logTarget, nameof(logTarget));
     _traceTarget = logTarget.Kind == LogTargetKind.Project ?
                    TraceTarget.ForProject(logTarget.ProjectId) : null;
     _consumer                   = GaxPreconditions.CheckNotNull(consumer, nameof(consumer));
     _loggerOptions              = GaxPreconditions.CheckNotNull(loggerOptions, nameof(loggerOptions));
     _logName                    = GaxPreconditions.CheckNotNullOrEmpty(logName, nameof(logName));
     _fullLogName                = logTarget.GetFullLogName(_loggerOptions.LogName);
     _serviceProvider            = serviceProvider;
     _clock                      = clock ?? SystemClock.Instance;
     _obsoleteTraceContextGetter = obsoleteTraceContextGetter;
     _ambientScopeManager        = new AmbientScopeManager(_loggerOptions, _serviceProvider, obsoleteLabelsGetter);
 }
Example #6
0
 private EventTarget(LogTarget target)
 {
     GaxPreconditions.CheckNotNull(target, nameof(target));
     Kind      = EventTargetKind.Logging;
     LogTarget = target;
 }