From 84b3e6f21e3ba4ea1febf7b8e096bd096cde82d5 Mon Sep 17 00:00:00 2001 From: sqdselo <147947144+sqdselo@users.noreply.github.com> Date: Mon, 6 May 2024 23:02:05 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=BF=D0=BA=D0=B0=D0=93=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D0=B2=D0=B0=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80?= =?UTF-8?q?=D0=B0=D1=82=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D0=B0=207?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCompany.cs | 2 +- .../HoistingCrane/FormCarCollection.cs | 10 ++++---- .../HoistingCrane/HoistingCrane.csproj | 5 +++- HoistingCrane/HoistingCrane/Program.cs | 24 ++++++++++++++----- HoistingCrane/HoistingCrane/serilog.json | 18 ++++++++++++++ ФайлДляЛабы.txt | 2 ++ 6 files changed, 48 insertions(+), 13 deletions(-) create mode 100644 HoistingCrane/HoistingCrane/serilog.json create mode 100644 ФайлДляЛабы.txt diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs index fb26d02..10711a6 100644 --- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs +++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs @@ -30,7 +30,7 @@ namespace HoistingCrane.CollectionGenericObjects { get { - return (pictureWidth * pictureHeight) / (_placeSizeHeight * _placeSizeWidth)-2; + return (pictureWidth / _placeSizeWidth) * (pictureHeight / _placeSizeHeight); } } public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects array) diff --git a/HoistingCrane/HoistingCrane/FormCarCollection.cs b/HoistingCrane/HoistingCrane/FormCarCollection.cs index 318a373..bde17ab 100644 --- a/HoistingCrane/HoistingCrane/FormCarCollection.cs +++ b/HoistingCrane/HoistingCrane/FormCarCollection.cs @@ -44,7 +44,7 @@ namespace HoistingCrane else { MessageBox.Show("Не удалось добавить объект"); - logger.LogInformation("Не удалось добавить корабль {ship} в коллекцию", drawningTrackedVehicle.GetType().Name); + logger.LogInformation("Не удалось добавить кран {crane} в коллекцию", drawningTrackedVehicle.GetType().Name); } } catch (CollectionOverflowException ex) @@ -142,12 +142,12 @@ namespace HoistingCrane if (radioButtonMassive.Checked) { collectionType = CollectionType.Massive; - logger.LogInformation("Создана коллекция '{nameCol}' , название: {name}", collectionType, textBoxCollectionName.Text); + logger.LogInformation("Создана коллекция {nameCol} , название: {name}", collectionType, textBoxCollectionName.Text); } else if (radioButtonList.Checked) { collectionType = CollectionType.List; - logger.LogInformation("Создана коллекция '{nameCol}' , название: {name}", collectionType, textBoxCollectionName.Text); + logger.LogInformation("Создана коллекция {nameCol} , название: {name}", collectionType, textBoxCollectionName.Text); } _storageCollection.AddCollection(textBoxCollectionName.Text,collectionType);RerfreshListBoxItems(); } @@ -205,7 +205,7 @@ namespace HoistingCrane { _storageCollection.SaveData(saveFileDialog.FileName); MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); - logger.LogInformation("Сохранение в файл: {filename}", saveFileDialog.FileName); + logger.LogInformation("Сохранение в файл: {filename}", saveFileDialog.FileName.ToString()); } catch (Exception ex) { @@ -229,7 +229,7 @@ namespace HoistingCrane _storageCollection.LoadData(openFileDialog.FileName); RerfreshListBoxItems(); MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); - logger.LogInformation("Загрузка в файл: {filename}", saveFileDialog.FileName); + logger.LogInformation("Загрузка из файла: {filename}", saveFileDialog.FileName.ToString()); } catch(Exception ex) { diff --git a/HoistingCrane/HoistingCrane/HoistingCrane.csproj b/HoistingCrane/HoistingCrane/HoistingCrane.csproj index 9b3b27e..3f2e375 100644 --- a/HoistingCrane/HoistingCrane/HoistingCrane.csproj +++ b/HoistingCrane/HoistingCrane/HoistingCrane.csproj @@ -13,8 +13,11 @@ + + - + + diff --git a/HoistingCrane/HoistingCrane/Program.cs b/HoistingCrane/HoistingCrane/Program.cs index 562ee2d..48fac59 100644 --- a/HoistingCrane/HoistingCrane/Program.cs +++ b/HoistingCrane/HoistingCrane/Program.cs @@ -1,8 +1,7 @@ +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Serilog; -using Serilog.Extensions.Logging; - namespace HoistingCrane { internal static class Program @@ -18,11 +17,24 @@ namespace HoistingCrane } private static void ConfigureServices(ServiceCollection services) { - // Serilog - Log.Logger = new LoggerConfiguration().WriteTo.File("E:\\myLog.log").CreateLogger(); - services.AddSingleton().AddLogging(builder => + + string[] path = Directory.GetCurrentDirectory().Split('\\'); + string pathNeed = ""; + for (int i = 0; i < path.Length - 3; i++) { - builder.AddSerilog(); + pathNeed += path[i] + "\\"; + } + + + services.AddSingleton() + .AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddSerilog(new LoggerConfiguration() + .ReadFrom.Configuration(new ConfigurationBuilder() + .AddJsonFile($"{pathNeed}serilog.json") + .Build()) + .CreateLogger()); }); } } diff --git a/HoistingCrane/HoistingCrane/serilog.json b/HoistingCrane/HoistingCrane/serilog.json new file mode 100644 index 0000000..a8648e8 --- /dev/null +++ b/HoistingCrane/HoistingCrane/serilog.json @@ -0,0 +1,18 @@ + +{ + "Serilog": { + "Using": [ "Serilog.Sinks.File" ], + "MinimumLevel": "Debug", + "WriteTo": [ + { + "Name": "File", + "Args": { + "path": "log.log" + } + } + ], + "Properties": { + "Application": "Sample" + } + } +} diff --git a/ФайлДляЛабы.txt b/ФайлДляЛабы.txt new file mode 100644 index 0000000..f37cd75 --- /dev/null +++ b/ФайлДляЛабы.txt @@ -0,0 +1,2 @@ +CollectionsStorage +массив|Massive|25|EntityTrackedVehicle:100:100:White;EntityTrackedVehicle:100:100:Yellow;EntityTrackedVehicle:100:100:Purple;EntityHoistingCrane:100:100:Gray:Black:True:False;EntityTrackedVehicle:100:100:White;EntityTrackedVehicle:100:100:White;EntityHoistingCrane:100:100:Green:Black:False:False;EntityTrackedVehicle:100:100:Gray;EntityTrackedVehicle:100:100:Red;EntityHoistingCrane:100:100:White:Black:False:False;EntityHoistingCrane:100:100:Green:Blue:True:False;EntityHoistingCrane:100:100:Black:Black:True:True;EntityTrackedVehicle:100:100:White;EntityTrackedVehicle:100:100:Purple;EntityTrackedVehicle:100:100:Black;EntityTrackedVehicle:100:100:Blue;EntityTrackedVehicle:100:100:Gray;EntityTrackedVehicle:100:100:Red;EntityTrackedVehicle:100:100:Purple;EntityTrackedVehicle:100:100:Green;EntityTrackedVehicle:100:100:Purple;EntityTrackedVehicle:100:100:Yellow;EntityTrackedVehicle:100:100:Blue;EntityTrackedVehicle:100:100:Gray; \ No newline at end of file