Exemplo n.º 1
0
        public static int Main(string[] args)
        {
            Serilog.Debugging.SelfLog.Enable(Console.Error);

            LoggerConfiguration config = new LoggerConfiguration()
                                         .ReadFrom.Configuration(Configuration);

            //Email logging setup
            EmailConfiguration emailConfig = new EmailConfiguration();

            Configuration.Bind("SerilogEmail", emailConfig);

            if (emailConfig.Enabled)
            {
                config.WriteTo.Email(emailConfig.ToEmailConnectionInfo(Env),
                                     outputTemplate: emailConfig.OutputTemplate,
                                     batchPostingLimit: emailConfig.BatchPostingLimit,
                                     restrictedToMinimumLevel: emailConfig.RestrictedToMinimumLevel
                                     );
            }

            Log.Logger = config.CreateLogger();
            ApplicationInfo info = ApplicationInfo.BuildApplicationInfo();

            try
            {
                AppLogging
                .ForCategory("Lifecycle")
                .Information("Startup of {Application} version {Version} built {BuildDate}",
                             info.ApplicationName,
                             info.ApplicationVersion,
                             info.ApplicationBuildDate);

                CreateWebHostBuilder(args).Build().Run();

                AppLogging
                .ForCategory("Lifecycle")
                .Information("Shutdown of {Application}", info.ApplicationName);

                return(0);
            }
            catch (Exception ex)
            {
                AppLogging
                .ForCategory("Lifecycle")
                .Fatal(ex, "Application {Application} terminated unexpectedly", info.ApplicationName);

                return(1);
            }
            finally
            {
                Log.CloseAndFlush();
            }
        }
Exemplo n.º 2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            string connectionString = Configuration.GetConnectionString("I don't even know. Just give me the data, okay?");

            //Normal context
            services.AddDbContext <DbCore>(options =>
                                           options.UseSqlServer(connectionString));
            //Transient-scoped context primarily for usage in isolating request logging from normal database activity
            services.AddDbContext <DbCoreTransient>(options =>
                                                    options.UseSqlServer(connectionString),
                                                    ServiceLifetime.Transient);
            //Identity context
            services.AddDbContext <IdentityCoreContext>(options =>
                                                        options.UseSqlServer(connectionString));

            services.AddDefaultIdentity <IdentityUser>()
            //.AddDefaultUI(UIFramework.Bootstrap3)
            .AddEntityFrameworkStores <IdentityCoreContext>();

            //Look for views in the MvcPages folder
            services.AddMvcPages();

            services.AddMvc()
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
            .AddRazorPagesOptions(options =>
            {
                options.AllowAreas = true;
                options.Conventions.AuthorizeAreaFolder("Identity", "/Account/Manage");
                options.Conventions.AuthorizeAreaPage("Identity", "/Account/Logout");
            });

            services.AddAntiforgery(opts => opts.Cookie.Name = "_PHP_XSRF_");

            services.GenericServicesSimpleSetup <DbCore>(Assembly.GetAssembly(typeof(Startup)));

            //Use older password hashing algorithm for compatibility with Identity non-core
            services.Configure <PasswordHasherOptions>(options => options.CompatibilityMode = PasswordHasherCompatibilityMode.IdentityV2);

            services.AddSingleton(ApplicationInfo.BuildApplicationInfo()
                                  .AddFriendlyDbName(connectionString, Configuration.GetSection("FriendlyDbNames")));

            ConfigureDi(services);
        }
Exemplo n.º 3
0
 // All the custom services that make up the API layer
 private void AddApiServices(IServiceCollection services)
 {
     services.AddSingleton(ApplicationInfo.BuildApplicationInfo());
 }