From fec308c18b3373aa0e703ce5d168d3e1ae0b1541 Mon Sep 17 00:00:00 2001 From: Kirill <117719052+KirillFirsof@users.noreply.github.com> Date: Tue, 26 Dec 2023 20:40:57 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9A=D0=BE=D0=BD=D0=B5=D1=86=207=D0=BE=D0=B9?= =?UTF-8?q?=20=D0=BB=D0=B0=D0=B1=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormTractorCollection.cs | 15 ++++--- .../RPP_FirstLaba_Tractor/Program.cs | 41 ++++++++----------- .../ProjectTractor.csproj | 2 +- .../RPP_FirstLaba_Tractor/g.txt | 0 4 files changed, 24 insertions(+), 34 deletions(-) create mode 100644 RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/g.txt diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs index 831db09..245df64 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs @@ -12,9 +12,9 @@ using ProjectTractor.DrawningObjects; using ProjectTractor.Generics; using ProjectTractor.MovementStrategy; using ProjectTractor.Exceptions; -using Microsoft.VisualBasic.Logging; using System.Xml.Linq; using System.Linq.Expressions; +using Serilog; namespace ProjectTractor { @@ -27,12 +27,10 @@ namespace ProjectTractor /// private readonly TractorsGenericStorage _storage; - private readonly ILogger _logger; - /// /// Конструктор /// - public FormTractorCollection(ILogger logger) + public FormTractorCollection() { InitializeComponent(); _storage = new TractorsGenericStorage(pictureBoxCollection.Width, @@ -76,7 +74,7 @@ namespace ProjectTractor } _storage.AddSet(textBoxStorageName.Text); ReloadObjects(); - _logger.LogInformation($"Добавлен набор: { textBoxStorageName.Text}"); + Log.Information($"Добавлен набор: {textBoxStorageName.Text}"); } /// /// Выбор набора @@ -107,7 +105,7 @@ namespace ProjectTractor { _storage.DelSet(name); ReloadObjects(); - _logger.LogInformation($"Удален набор: {name}"); + Log.Information($"Удален набор: {name}"); } } @@ -136,6 +134,7 @@ namespace ProjectTractor if (isAdditionSuccessful) { MessageBox.Show("Объект добавлен"); + Log.Information($"Добавлен объект в коллекцию {listBoxStorages.SelectedItem.ToString() ?? string.Empty}"); m.ChangePictureBoxSize(pictureBoxCollection.Width, pictureBoxCollection.Height); pictureBoxCollection.Image = obj.ShowTractors(); } @@ -244,7 +243,7 @@ namespace ProjectTractor _storage.LoadData(openFileDialog.FileName); MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); - _logger.LogInformation("Загрузка прошла успешно:"); + Log.Information("Загрузка прошла успешно:"); foreach (var collection in _storage.Keys) { listBoxStorages.Items.Add(collection); @@ -253,7 +252,7 @@ namespace ProjectTractor } catch (Exception ex) { - _logger.LogWarning("Не удалось загрузить"); + Log.Warning("Не удалось загрузить"); MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); } } diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/Program.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/Program.cs index 94e4901..5bf42a7 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/Program.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/Program.cs @@ -8,39 +8,30 @@ namespace ProjectTractor { internal static class Program { + /// + /// The main entry point for the application. + /// [STAThread] static void Main() { - // To customize application configuration such as set high DPI settings or default font, - // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - var services = new ServiceCollection(); - ConfigureServices(services); - using (ServiceProvider serviceProvider = services.BuildServiceProvider()) + string[] path = Directory.GetCurrentDirectory().Split('\\'); + string pathNeed = ""; + for (int i = 0; i < path.Length - 3; i++) { - Application.Run(serviceProvider.GetRequiredService()); + pathNeed += path[i] + "\\"; } - } - private static void ConfigureServices(ServiceCollection services) - { - services.AddSingleton().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() + var configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile("appsettings.json") - .AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", true) + .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); - }); + Log.Logger = new LoggerConfiguration() + .ReadFrom.Configuration(configuration) + .CreateLogger(); + Application.SetHighDpiMode(HighDpiMode.SystemAware); + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new FormTractorCollection()); } } } \ No newline at end of file diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/ProjectTractor.csproj b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/ProjectTractor.csproj index 83002d2..858ead4 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/ProjectTractor.csproj +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/ProjectTractor.csproj @@ -40,6 +40,6 @@ - + \ No newline at end of file diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/g.txt b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/g.txt new file mode 100644 index 0000000..e69de29