62 lines
2.1 KiB
C#
62 lines
2.1 KiB
C#
try
|
|
{
|
|
var configuration = new ConfigurationBuilder()
|
|
.SetBasePath(Directory.GetCurrentDirectory())
|
|
.AddJsonFile("Serilog.json")
|
|
.AddJsonFile($"Serilog.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", true)
|
|
.Build();
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
var logger = new LoggerConfiguration()
|
|
.ReadFrom.Configuration(configuration)
|
|
.WriteTo.Exceptionless(builder.Configuration.GetValue<string>("Exceptionless:ApiKey"), builder.Configuration.GetValue<string>("Exceptionless:ServerUrl"), new string[] { "crm-external-web" })
|
|
.CreateLogger();
|
|
Log.Logger = logger;
|
|
|
|
builder.Services.AddLogging(logging =>
|
|
{
|
|
logging.ClearProviders();
|
|
logging.AddSerilog(logger);
|
|
});
|
|
// Add services to the container.
|
|
builder.Services.AddControllersWithViews();
|
|
builder.Services
|
|
.AddAutoIoc(typeof(IScopedDependency), LifeCycle.Scoped)
|
|
.AddAutoIoc(typeof(ISingletonDependency), LifeCycle.Singleton)
|
|
.AddAutoIoc(typeof(ITransientDependency), LifeCycle.Transient)
|
|
.AddMapper();
|
|
builder.Services.AddDGEntityFrameworkOracle<CrmDbContext>("appid");
|
|
builder.Services.AddDGHttpClient();
|
|
builder.Services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
|
builder.Services.AddRedis(builder.Configuration);
|
|
var app = builder.Build();
|
|
|
|
// Configure the HTTP request pipeline.
|
|
if (!app.Environment.IsDevelopment())
|
|
{
|
|
app.UseExceptionHandler("/Home/Error");
|
|
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
|
app.UseHsts();
|
|
}
|
|
|
|
app.UseHttpsRedirection();
|
|
app.UseStaticFiles();
|
|
app.UseDGEntityFrameworkOracle("crm_tg_dng8");
|
|
app.UseRouting();
|
|
|
|
app.UseAuthorization();
|
|
|
|
app.MapControllerRoute(
|
|
name: "default",
|
|
pattern: "{controller=Home}/{action=Index}/{id?}");
|
|
|
|
app.Run();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Fatal(ex, "Host terminated unexpectedly");
|
|
}
|
|
finally
|
|
{
|
|
Log.CloseAndFlush();
|
|
}
|