/// <summary> /// Adds services for middleware that will report all uncaught exceptions to the /// Google Cloud Error Reporting API. /// <para> /// Can be used when running on Google App Engine or Google Compute Engine. /// The Google Cloud Platform project to report errors to will detected from the /// current platform. /// </para> /// </summary> /// <param name="services">The service collection. Must not be null.</param> /// <param name="setupAction">Action to set up options. Must not be null.</param> /// <remarks> /// If <see cref="RetryOptions.ExceptionHandling"/> is set to <see cref="ExceptionHandling.Propagate"/> /// and the <see cref="RequestDelegate"/> executed by this middleware throws an exception and this /// diagnostics library also throws an exception trying to report it an <see cref="AggregateException"/> /// with both exceptions will be thrown. Otherwise only the exception from the <see cref="RequestDelegate"/> /// will be thrown. /// </remarks> public static IServiceCollection AddGoogleExceptionLogging( this IServiceCollection services, Action <ErrorReportingServiceOptions> setupAction) { GaxPreconditions.CheckNotNull(services, nameof(services)); GaxPreconditions.CheckNotNull(setupAction, nameof(setupAction)); var serviceOptions = new ErrorReportingServiceOptions(); setupAction(serviceOptions); services.AddHttpContextAccessor(); services.AddSingleton(ContextExceptionLogger.Create( serviceOptions.ProjectId, serviceOptions.ServiceName, serviceOptions.Version, serviceOptions.Options)); return(services.AddSingleton(CreateExceptionLogger)); }
public static IServiceCollection AddGoogleExceptionLogging( this IServiceCollection services, Action <ErrorReportingServiceOptions> setupAction) { GaxPreconditions.CheckNotNull(services, nameof(services)); GaxPreconditions.CheckNotNull(setupAction, nameof(setupAction)); var serviceOptions = new ErrorReportingServiceOptions(); setupAction(serviceOptions); return(services.AddGoogleErrorReportingForAspNetCore(registerMiddleware: false, new Common.ErrorReportingServiceOptions { ProjectId = serviceOptions.ProjectId, ServiceName = serviceOptions.ServiceName, Version = serviceOptions.Version, Options = serviceOptions.Options })); }