лаба 7 - В С Ё! (надеюсь)

This commit is contained in:
antoc0der 2023-12-06 20:07:21 +03:00
parent 4d7de8d19c
commit 793ecd010e
2 changed files with 19 additions and 29 deletions

View File

@ -1,20 +1,15 @@
{ {
"Serilog": { "Serilog": {
"Using": [ "Serilog.Sinks.File" ], "Using": [ "Serilog.Sinks.File" ],
"MinimumLevel": "Information", "MinimumLevel": "Debug",
"WriteTo": [ "WriteTo": [
{ {
"Name": "File", "Name": "File",
"Args": { "Args": { "path": "log.txt" }
"path": "Logs/log_.log",
"rollingInterval": "Day",
"outputTemplate": "[{Timestamp:HH:mm:ss.fff}]{Level:u4}: {Message:lj}{NewLine}{Exception}"
}
} }
], ],
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
"Properties": { "Properties": {
"Application": "ProjectAirplaneWithRadar" "Application": "Sample"
} }
} }
} }

View File

@ -25,29 +25,24 @@ namespace ProjectAirplaneWithRadar
static void Main() static void Main()
{ {
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
//Application.Run(new FormAirplanesCollection()); string[] path = Directory.GetCurrentDirectory().Split('\\');
var services = new ServiceCollection(); string pathNeed = "";
ConfigureServices(services); for (int i = 0; i < path.Length - 3; i++)
using (ServiceProvider serviceProvider = services.BuildServiceProvider())
{ {
Application.Run(serviceProvider.GetRequiredService<FormAirplanesCollection>()); pathNeed += path[i] + "\\";
} }
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile(path: $"{pathNeed}AppSettings.json", optional: false, reloadOnChange: true)
.Build();
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
.CreateLogger();
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FormAirplanesCollection());
} }
private static void ConfigureServices(ServiceCollection services)
{
services.AddSingleton<FormAirplanesCollection>().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}appsettings.json", optional: false, reloadOnChange: true).Build();
var logger = new LoggerConfiguration().ReadFrom.Configuration(configuration).CreateLogger();
option.SetMinimumLevel(LogLevel.Information);
option.AddSerilog(logger);
});
}
} }
} }