72 lines
2.1 KiB
C#
72 lines
2.1 KiB
C#
using DIDemoLib;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
using WinFormDiApp.DAL;
|
|
using WinFormDiApp.DAL.Data;
|
|
using Serilog;
|
|
using Serilog.Formatting.Json;
|
|
|
|
namespace WinFormDiApp
|
|
{
|
|
internal static class Program
|
|
{
|
|
/// <summary>
|
|
/// The main entry point for the application.
|
|
/// </summary>
|
|
[STAThread]
|
|
static void Main(string[] args)
|
|
{
|
|
Log.Logger = new LoggerConfiguration()
|
|
.WriteTo.Console()
|
|
.WriteTo.File(@"D:\logs\winformApp.txt",restrictedToMinimumLevel:Serilog.Events.LogEventLevel.Information,
|
|
rollingInterval: RollingInterval.Day)
|
|
.CreateLogger();
|
|
|
|
var host = ContainerConfig.Configure(CreateHostBuilder(args));
|
|
|
|
using var scope = host.Services.CreateScope();
|
|
|
|
try
|
|
{
|
|
Log.Information("Starting of service..");
|
|
|
|
var services = scope.ServiceProvider;
|
|
|
|
var context = services.GetRequiredService<ApplicationDbContext>();
|
|
DataSeeder.Initialize(context);
|
|
|
|
Application.EnableVisualStyles();
|
|
Application.SetCompatibleTextRenderingDefault(false);
|
|
Application.SetHighDpiMode(HighDpiMode.SystemAware);
|
|
|
|
var frm = services.GetRequiredService<MainWindow>();
|
|
Application.Run(frm);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Fatal(ex, "Exception in application");
|
|
}
|
|
finally
|
|
{
|
|
Log.Information("Exiting service..");
|
|
Log.CloseAndFlush();
|
|
}
|
|
|
|
}
|
|
|
|
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
|
Host.CreateDefaultBuilder(args)
|
|
.UseSerilog()
|
|
.ConfigureLogging((context, logging) =>
|
|
{
|
|
logging.ClearProviders();
|
|
logging.AddConfiguration(context.Configuration.GetSection("Logging"));
|
|
logging.AddConsole();
|
|
logging.AddDebug();
|
|
});
|
|
|
|
|
|
|
|
}
|
|
} |