Beispiel #1
0
 /// <summary>
 /// Configures Google Diagnostics to be used in 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 AddGoogleDiagnosticsForAspNetCore(
     this IServiceCollection services,
     AspNetCoreTraceOptions traceOptions  = null,
     LoggingServiceOptions loggingOptions = null,
     Common.ErrorReportingServiceOptions errorReportingOptions = null) =>
 services
 .AddLogEntryLabelProviderSingleton <TraceIdLogEntryLabelProvider>()
 .AddGoogleTraceForAspNetCore(traceOptions)
 .AddLogging(builder => builder.AddGoogle(loggingOptions))
 .AddGoogleErrorReportingForAspNetCore(errorReportingOptions);
        internal static IServiceCollection AddGoogleErrorReportingForAspNetCore(
            this IServiceCollection services, bool registerMiddleware, Common.ErrorReportingServiceOptions options)
        {
            services.AddGoogleErrorReporting(options);
            services.AddHttpContextAccessor();
            services.AddSingleton <IExceptionLogger>(sp => new GoogleExceptionLogger(
                                                         sp.GetRequiredService <IContextExceptionLogger>(),
                                                         sp.GetRequiredService <IHttpContextAccessor>()));

            if (registerMiddleware)
            {
                // This registers the trace middleware so users don't have to.
                services.AddSingleton <IStartupFilter, AspNetCoreErrorReportingStartupFilter>();
            }

            return(services);
        }
        /// <summary>
        /// Configures Google Cloud Error Reporting for ASP .NET Core applications./>.
        /// </summary>
        public static IServiceCollection AddGoogleErrorReportingForAspNetCore(
            this IServiceCollection services, Common.ErrorReportingServiceOptions options = null) =>
#pragma warning disable CS0618 // Type or member is obsolete
        services.AddGoogleErrorReportingForAspNetCore(true, options);