public HomeController(ILogger <HomeController> logger, IConfiguration configuration, IHttpContextAccessor httpContextAccessor, Serilog.ILogger serilogLogger, IOptions <CryptographyCertificate> optionsAccessor, IOptions <AppOptions> optionsAccessor2) { _logger = logger; _configuration = configuration; _httpContextAccessor = httpContextAccessor; _serilogLogger = serilogLogger; _cryptographyCertificate = optionsAccessor.Value; _appOptions = optionsAccessor2.Value; }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // Add framework services. services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); services.AddIdentity <ApplicationUser, IdentityRole>() .AddEntityFrameworkStores <ApplicationDbContext>() .AddDefaultTokenProviders(); services.AddOptions(); services.Configure <CryptographyCertificate>(Configuration.GetSection("CryptographyCertificate")); services.Configure <AppOptions>(Configuration.GetSection("app")); services.AddMvc(); // Add application services. services.AddTransient <IEmailSender, AuthMessageSender>(); services.AddTransient <ISmsSender, AuthMessageSender>(); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddSingleton <IConfiguration>(Configuration); //var columnOptions = new ColumnOptions //{ // AdditionalDataColumns = new Collection<DataColumn> // { // new DataColumn {DataType = typeof (string), ColumnName = "User", AllowDBNull = true}, // new DataColumn {DataType = typeof (string), ColumnName = "Other", AllowDBNull = true}, // } //}; //columnOptions.Store.Add(StandardColumn.LogEvent); var x = Configuration["Serilog:ConnectionString"]; var y = Configuration["Serilog:TableName"]; var key1 = Configuration["key1"]; var cryptographyCertificate = new CryptographyCertificate(); Configuration.GetSection("CryptographyCertificate").Bind(cryptographyCertificate); var findValue = cryptographyCertificate.FindValue; var appOptions = Configuration.GetSection("app").Get <AppOptions>(); var height = appOptions.Window.Height; var cryptographyCertificate2 = Configuration.GetSection("CryptographyCertificate").Get <CryptographyCertificate>(); var findValue2 = cryptographyCertificate2.FindValue; Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) .MinimumLevel.Override("System", LogEventLevel.Error) .WriteTo.RollingFile(@"C:\temp\WebApplicationCore.Portal-Serilog-{Date}.txt") .WriteTo.MSSqlServer(Configuration["Serilog:ConnectionString"] , Configuration["Serilog:TableName"] , LogEventLevel.Debug //, columnOptions: columnOptions , autoCreateSqlTable: true) .CreateLogger(); services.AddSingleton <Serilog.ILogger>(Log.Logger); //services.AddSingleton<Serilog.ILogger> //(x => new LoggerConfiguration() // .MinimumLevel.Debug() // .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) // .MinimumLevel.Override("System", LogEventLevel.Error) // .WriteTo.RollingFile(@"C:\temp\WebApplicationCore.Portal-Serilog-{Date}.txt") // .CreateLogger()); }