PIBD14-BOYKO-M.S.SuperEasyS.../ProjectElectroTrans/Program.cs

45 lines
1.7 KiB
C#
Raw Normal View History

2024-04-24 23:26:19 +04:00
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Configuration;
using Serilog;
2024-03-13 19:49:07 +04:00
2024-02-28 23:06:50 +04:00
namespace ProjectElectroTrans
2024-02-14 15:48:47 +04:00
{
2024-02-14 15:51:28 +04:00
internal static class Program
2024-02-14 15:48:47 +04:00
{
2024-02-14 15:51:28 +04:00
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
2024-04-24 23:26:19 +04:00
var services = new ServiceCollection();
ConfigureServices(services);
using (ServiceProvider serviceProvider = services.BuildServiceProvider())
{
Application.Run(serviceProvider.GetRequiredService<FormTransCollection>());
}
2024-02-14 15:51:28 +04:00
}
2024-03-13 19:49:07 +04:00
2024-04-24 23:26:19 +04:00
private static void ConfigureServices(ServiceCollection services)
{
services.AddSingleton<FormTransCollection>().AddLogging(option =>
{
string[] path = Directory.GetCurrentDirectory().Split('\\');
string pathNeed = "";
for (int i = 0; i < path.Length - 3; i++)
{
pathNeed += path[i] + "\\";
}
var configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile(path: $"{pathNeed}serilogConfig.json", optional: false, reloadOnChange: true)
.Build();
var logger = new LoggerConfiguration().ReadFrom.Configuration(configuration).CreateLogger();
option.SetMinimumLevel(LogLevel.Information);
option.AddSerilog(logger);
});
}
}
2024-02-14 15:48:47 +04:00
}