/// <summary> /// Creates an instance of <see cref="ErrorReportingExceptionFilter"/> using credentials as /// defined by <see cref="GoogleCredential.GetApplicationDefaultAsync"/>. /// <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="serviceName">An identifier of the service, such as the name of the executable or job. /// Cannot be null.</param> /// <param name="version">Represents the source code version that the developer provided. /// Cannot be null.</param> /// <param name="options">Optional, error reporting options.</param> public static ErrorReportingExceptionFilter Create( string serviceName, string version, ErrorReportingOptions options = null) { var contextLogger = ErrorReportingContextExceptionLogger.Create(null, serviceName, version, options); return(new ErrorReportingExceptionFilter(contextLogger)); }
/// <summary> /// Shared code for creating error reporting services. /// </summary> /// <param name="services">The service collection. Cannot be null.</param> /// <param name="projectId">The Google Cloud Platform project ID. If null the project Id will be auto detected.</param> /// <param name="serviceName">An identifier of the service, such as the name of the executable or job. /// Cannot be null.</param> /// <param name="version">Represents the source code version that the developer provided. /// Cannot be null.</param> /// <param name="options">Optional, error reporting options.</param> private static void AddGoogleExceptionLoggingBase( this IServiceCollection services, string projectId, string serviceName, string version, ErrorReportingOptions options = null) { services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddSingleton(ErrorReportingContextExceptionLogger.Create(projectId, serviceName, version, options)); services.AddSingleton(CreateExceptionLogger); }
/// <summary> /// Creates an instance of <see cref="ErrorReportingExceptionFilter"/> using credentials as /// defined by <see cref="GoogleCredential.GetApplicationDefaultAsync"/>. /// </summary> /// <param name="projectId">The Google Cloud Platform project ID. Cannot be null.</param> /// <param name="serviceName">An identifier of the service, such as the name of the executable or job. /// Cannot be null.</param> /// <param name="version">Represents the source code version that the developer provided. /// Cannot be null.</param> /// <param name="options">Optional, error reporting options.</param> public static ErrorReportingExceptionFilter Create(string projectId, string serviceName, string version, ErrorReportingOptions options = null) { GaxPreconditions.CheckNotNullOrEmpty(projectId, nameof(projectId)); var contextLogger = ErrorReportingContextExceptionLogger.Create(projectId, serviceName, version, options); return(new ErrorReportingExceptionFilter(contextLogger)); }
/// <summary> /// Adds services for middleware that will report all uncaught exceptions to the /// Stackdriver 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. Cannot be null.</param> /// <param name="setupAction">Action to set up options. Cannot be null.</param> public static void AddGoogleExceptionLogging( this IServiceCollection services, Action <ErrorReportingServiceOptions> setupAction) { GaxPreconditions.CheckNotNull(services, nameof(services)); GaxPreconditions.CheckNotNull(setupAction, nameof(setupAction)); var serviceOptions = new ErrorReportingServiceOptions(); setupAction(serviceOptions); var serviceName = GaxPreconditions.CheckNotNull(serviceOptions.ServiceName, nameof(serviceOptions.ServiceName)); var version = GaxPreconditions.CheckNotNull(serviceOptions.Version, nameof(serviceOptions.Version)); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddSingleton(ErrorReportingContextExceptionLogger.Create( serviceOptions.ProjectId, serviceName, version, serviceOptions.Options)); services.AddSingleton(CreateExceptionLogger); }