Beispiel #1
0
        internal static IContextExceptionLogger Create(ErrorReportingServiceOptions options, IServiceProvider serviceProvider)
        {
            options = options ?? new ErrorReportingServiceOptions();
            var errorReportingOptions = options.Options ?? ErrorReportingOptions.CreateInstance();

            var eventTarget = options.EventTarget
#pragma warning disable CS0618 // Type or member is obsolete
                              ?? errorReportingOptions.EventTarget
#pragma warning restore CS0618 // Type or member is obsolete
                              ?? EventTarget.ForProject(Project.GetAndCheckProjectId(null, errorReportingOptions.MonitoredResource));

            var client = options.Client
#pragma warning disable CS0618 // Type or member is obsolete
                         ?? eventTarget.LoggingClient
#pragma warning restore CS0618 // Type or member is obsolete
                         ?? LoggingServiceV2Client.Create();

            var serviceContext = CreateServiceContext(
                Project.GetServiceName(options.ServiceName, errorReportingOptions.MonitoredResource),
                Project.GetServiceName(options.Version, errorReportingOptions.MonitoredResource))
                                 ?? new Struct();

            IConsumer <LogEntry> consumer = LogConsumer.Create(client, errorReportingOptions.BufferOptions, errorReportingOptions.RetryOptions);

            return(new ErrorReportingContextExceptionLogger(consumer, eventTarget, serviceContext, errorReportingOptions, serviceProvider));
        }
 /// <summary>
 /// Configures Google Diagnostics to be used in non ASP.NET Core applications.
 /// </summary>
 /// <remarks>
 /// Options may be null in which case defaults will be used. Note that the
 /// Google Cloud Project ID to use is required. If not set via options, it will be
 /// obtained from the environment, but only if running on GCP.
 /// </remarks>
 public static IServiceCollection AddGoogleDiagnostics(
     this IServiceCollection services,
     TraceServiceOptions traceOptions     = null,
     LoggingServiceOptions loggingOptions = null,
     ErrorReportingServiceOptions errorReportingOptions = null) => services
 .AddGoogleTrace(traceOptions)
 .AddLogging(builder => builder.AddGoogle(loggingOptions))
 .AddGoogleErrorReporting(errorReportingOptions);
 /// <summary>
 /// Creates an <see cref="IContextExceptionLogger"/>.
 /// </summary>
 /// <param name="options">The error reporting options. May be null, in which case defaults will be used, in
 /// particular, if running on Google Cloud, the Google Cloud project ID to log to will be detected from
 /// the platform.</param>
 /// <param name="serviceProvider">The service provider to obtain services from. May be null,
 /// in which case some context information won't be added to the LogEntry.</param>
 /// <returns>An <see cref="IContextExceptionLogger"/> for the given options.</returns>
 public static IContextExceptionLogger Create(ErrorReportingServiceOptions options, IServiceProvider serviceProvider) =>
 ErrorReportingContextExceptionLogger.Create(options, serviceProvider);
Beispiel #4
0
 /// <summary>
 /// Registers the Error Reporting component for Dependency Injection.
 /// </summary>
 public static IServiceCollection AddGoogleErrorReporting(this IServiceCollection services, ErrorReportingServiceOptions options = null) =>
 services.AddSingleton(serviceProvider =>
                       ContextExceptionLogger.Create(options, serviceProvider));