Example #1
0
        public static IWebHost BuildWebHost(string[] args)
        {
            var webHost = WebHost.CreateDefaultBuilder(args)
                          .UseStartup <Startup>()
                          .UseNLog();

            string sentryDSN;

            CoreUtils.GetConfigFromEnviromentVariable("Sentry_DSN", string.Empty, out sentryDSN);

            if (!string.IsNullOrEmpty(sentryDSN))
            {
                webHost.UseSentry(opt =>
                {
                    opt.Init(i =>
                    {
                        bool sentryIncludeRequestPayload = true;
                        bool sentryIncludeActivityData   = true;
                        LogLevel sentryMinimumBreadcrumbLevel;
                        LogLevel sentryMinimumEventLevel;

                        CoreUtils.GetConfigFromEnviromentVariable("Sentry_IncludeRequestPayload", true, out sentryIncludeRequestPayload);
                        CoreUtils.GetConfigFromEnviromentVariable("Sentry_IncludeActivityData", true, out sentryIncludeActivityData);
                        CoreUtils.GetConfigFromEnviromentVariable("Sentry_MinimumBreadcrumbLevel", LogLevel.Error, out sentryMinimumBreadcrumbLevel);
                        CoreUtils.GetConfigFromEnviromentVariable("Sentry_MinimumEventLevel", LogLevel.Error, out sentryMinimumEventLevel);
                        opt.Dsn = sentryDSN;
                        opt.IncludeRequestPayload = sentryIncludeRequestPayload;
                        opt.IncludeActivityData   = sentryIncludeActivityData;
                        opt.Logging = new Sentry.AspNetCore.LoggingOptions()
                        {
                            MinimumBreadcrumbLevel = sentryMinimumBreadcrumbLevel,
                            MinimumEventLevel      = sentryMinimumEventLevel,
                        };
                        opt.Release = typeof(Startup).GetTypeInfo().Assembly.GetCustomAttribute <AssemblyFileVersionAttribute>().Version;
                        i.AddInAppExclude("Full");
                    });
                });
            }

            return(webHost.Build());
        }