From c60abd65d74ade092824e29a42c5bfefc48be6a3 Mon Sep 17 00:00:00 2001 From: cyxaruk Date: Mon, 6 May 2024 14:07:43 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=207?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCompany.cs | 31 +++-- .../CollectionGenericObjects/Autopark.cs | 30 +++-- .../ListGenericObjects.cs | 21 +++- .../MassiveGenericObjects.cs | 44 +++++-- .../StorageCollection.cs | 31 ++--- .../Exceptions/CollectionOverflowException.cs | 21 ++++ .../Exceptions/ObjectNotFoundException.cs | 21 ++++ .../PositionOutOfCollectionException.cs | 22 ++++ .../FormGasMachineCollection.Designer.cs | 12 +- .../ProjectCar/FormGasMachineCollection.cs | 76 ++++++++---- .../ProjectCar/FormGasMachineCollection.resx | 3 + ProjectCar/ProjectCar/Program.cs | 26 +++- .../ProjectCar/ProjectGasMachine.csproj | 18 +++ ProjectCar/ProjectCar/serilogConfig.json | 25 ++++ log20240506.txt | 115 ++++++++++++++++++ 15 files changed, 417 insertions(+), 79 deletions(-) create mode 100644 ProjectCar/ProjectCar/Exceptions/CollectionOverflowException.cs create mode 100644 ProjectCar/ProjectCar/Exceptions/ObjectNotFoundException.cs create mode 100644 ProjectCar/ProjectCar/Exceptions/PositionOutOfCollectionException.cs create mode 100644 ProjectCar/ProjectCar/serilogConfig.json create mode 100644 log20240506.txt diff --git a/ProjectCar/ProjectCar/CollectionGenericObjects/AbstractCompany.cs b/ProjectCar/ProjectCar/CollectionGenericObjects/AbstractCompany.cs index f7a1147..47de47a 100644 --- a/ProjectCar/ProjectCar/CollectionGenericObjects/AbstractCompany.cs +++ b/ProjectCar/ProjectCar/CollectionGenericObjects/AbstractCompany.cs @@ -1,4 +1,5 @@ using ProjectGasMachine.Drawnings; +using ProjectGasMachine.Exceptions; using System; using System.Collections.Generic; using System.Linq; @@ -87,14 +88,21 @@ public abstract class AbstractCompany public DrawningMachine? GetRandomObject() { Random rnd = new(); - return _collection?.Get(rnd.Next(GetMaxCount)); + try + { + return _collection?.Get(rnd.Next(GetMaxCount)); + } + catch (ObjectNotFoundException) + { + return null; + } } - /// - /// Вывод всей коллекции - /// - /// - public Bitmap? Show() + /// + /// Вывод всей коллекции + /// + /// + public Bitmap? Show() { Bitmap bitmap = new(_pictureWidth, _pictureHeight); Graphics graphics = Graphics.FromImage(bitmap); @@ -103,8 +111,15 @@ public abstract class AbstractCompany SetObjectsPosition(); for (int i = 0; i < (_collection?.Count ?? 0); ++i) { - DrawningMachine? obj = _collection?.Get(i); - obj?.DrawTransport(graphics); + try + { + DrawningMachine? obj = _collection?.Get(i); + obj?.DrawTransport(graphics); + } + catch (ObjectNotFoundException) + { + continue; + } } return bitmap; diff --git a/ProjectCar/ProjectCar/CollectionGenericObjects/Autopark.cs b/ProjectCar/ProjectCar/CollectionGenericObjects/Autopark.cs index 0aa791e..04ccda4 100644 --- a/ProjectCar/ProjectCar/CollectionGenericObjects/Autopark.cs +++ b/ProjectCar/ProjectCar/CollectionGenericObjects/Autopark.cs @@ -1,4 +1,5 @@ using ProjectGasMachine.Drawnings; +using ProjectGasMachine.Exceptions; using System; using System.Collections.Generic; using System.Linq; @@ -41,21 +42,28 @@ public class Autopark : AbstractCompany for (int i = 0; i < (_collection?.Count ?? 0); i++) { - if (_collection?.Get(i) != null) + try { - int x = 5 + _placeSizeWidth * n; - int y = (-3 + _placeSizeHeight * (_pictureHeight / _placeSizeHeight - 1)) - _placeSizeHeight * m; + if (_collection?.Get(i) != null) + { + int x = 5 + _placeSizeWidth * n; + int y = (-3 + _placeSizeHeight * (_pictureHeight / _placeSizeHeight - 1)) - _placeSizeHeight * m; - _collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight); - _collection?.Get(i)?.SetPosition(x, y); + _collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight); + _collection?.Get(i)?.SetPosition(x, y); + } + + if (n < _pictureWidth / _placeSizeWidth) + n++; + else + { + n = 0; + m++; + } } - - if (n < _pictureWidth / _placeSizeWidth) - n++; - else + catch (ObjectNotFoundException) { - n = 0; - m++; + break; } } } diff --git a/ProjectCar/ProjectCar/CollectionGenericObjects/ListGenericObjects.cs b/ProjectCar/ProjectCar/CollectionGenericObjects/ListGenericObjects.cs index 0ac85cf..ec822ac 100644 --- a/ProjectCar/ProjectCar/CollectionGenericObjects/ListGenericObjects.cs +++ b/ProjectCar/ProjectCar/CollectionGenericObjects/ListGenericObjects.cs @@ -1,4 +1,6 @@  +using ProjectGasMachine.Exceptions; + namespace ProjectGasMachine.CollectionGenericObjects; /// @@ -35,9 +37,10 @@ public class ListGenericObjects : ICollectionGenericObjects public T? Get(int position) { + // TODO выброс ошибки, если выход за границы списка if (position < 0 || position >= Count) { - return null; + throw new PositionOutOfCollectionException(position); } return _collection[position]; @@ -45,9 +48,10 @@ public class ListGenericObjects : ICollectionGenericObjects public int Insert(T obj) { + // TODO выброс ошибки, если переполнение if (Count == _maxCount) { - return -1; + throw new CollectionOverflowException(Count); } _collection.Add(obj); @@ -56,9 +60,15 @@ public class ListGenericObjects : ICollectionGenericObjects public int Insert(T obj, int position) { - if (Count == _maxCount || position < 0 || position > Count) + // TODO выброс ошибки, если выход за границы списка + // TODO выброс ошибки, если переполнение + if (position < 0 || position > Count) { - return -1; + throw new PositionOutOfCollectionException(position); + } + if (Count == _maxCount) + { + throw new CollectionOverflowException(Count); } _collection.Insert(position, obj); @@ -67,9 +77,10 @@ public class ListGenericObjects : ICollectionGenericObjects public T? Remove(int position) { + // TODO выброс ошибки, если выход за границы списка if (position < 0 || position > Count) { - return null; + throw new PositionOutOfCollectionException(position); } T? obj = _collection[position]; diff --git a/ProjectCar/ProjectCar/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectCar/ProjectCar/CollectionGenericObjects/MassiveGenericObjects.cs index 0898dfa..04bf4a1 100644 --- a/ProjectCar/ProjectCar/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/ProjectCar/ProjectCar/CollectionGenericObjects/MassiveGenericObjects.cs @@ -1,4 +1,7 @@  +using ProjectGasMachine.Exceptions; +using System.Linq; + namespace ProjectGasMachine.CollectionGenericObjects; /// @@ -51,17 +54,24 @@ public class MassiveGenericObjects : ICollectionGenericObjects public T? Get(int position) { - if (position < 0 || position > Count) + // TODO выброс ошибки, если выход за границы массива + // TODO выброс ошибки, если объект пустой + if (position < 0 || position >= Count) { - return null; + throw new PositionOutOfCollectionException(position); } + if (_collection[position] == null) + { + throw new ObjectNotFoundException(position); + } + return _collection[position]; } - + public int Insert(T obj) { - // TODO вставка в свободное место набора + // TODO выброс ошибки, если переполнение for (int i = 0; i < Count; i++) { if (_collection[i] == null) @@ -70,13 +80,17 @@ public class MassiveGenericObjects : ICollectionGenericObjects return i; } } - return -1; + + throw new CollectionOverflowException(Count); } + public int Insert(T obj, int position) { - if (position < 0 || position > Count) + // TODO выброс ошибки, если выход за границы массива + // TODO выброс ошибки, если переполнение + if (position < 0 || position >= Count) { - return -1; + throw new PositionOutOfCollectionException(position); } if (_collection[position] == null) @@ -90,7 +104,7 @@ public class MassiveGenericObjects : ICollectionGenericObjects if (_collection[i] == null) { _collection[i] = obj; - return position; + return i; } } @@ -99,19 +113,25 @@ public class MassiveGenericObjects : ICollectionGenericObjects if (_collection[i] == null) { _collection[i] = obj; - return position; + return i; } } - return -1; + throw new CollectionOverflowException(Count); } public T? Remove(int position) { - if (position < 0 || position > Count || _collection[position] == null) + // TODO выброс ошибки, если выход за границы массива + // TODO выброс ошибки, если объект пустой + if (position < 0 || position >= Count) { - return null; + throw new PositionOutOfCollectionException(position); + } + if (_collection[position] == null) + { + throw new ObjectNotFoundException(position); } T? obj = _collection[position]; diff --git a/ProjectCar/ProjectCar/CollectionGenericObjects/StorageCollection.cs b/ProjectCar/ProjectCar/CollectionGenericObjects/StorageCollection.cs index 4c3ccdc..8c1bbc4 100644 --- a/ProjectCar/ProjectCar/CollectionGenericObjects/StorageCollection.cs +++ b/ProjectCar/ProjectCar/CollectionGenericObjects/StorageCollection.cs @@ -1,4 +1,5 @@ using ProjectGasMachine.Drawnings; +using ProjectGasMachine.Exceptions; namespace ProjectGasMachine.CollectionGenericObjects; @@ -100,12 +101,11 @@ public class StorageCollection /// Сохранение информации по автомобилям в хранилище в файл /// /// Путь и имя файла - /// true - сохранение прошло успешно, false - ошибка при сохранении данных - public bool SaveData(string filename) + public void SaveData(string filename) { if (_storages.Count == 0) { - return false; + throw new NullReferenceException("В хранилище отсутствуют коллекции для сохранения"); } if (File.Exists(filename)) @@ -147,19 +147,17 @@ public class StorageCollection } } - return true; } /// /// Загрузка информации по автомобилям в хранилище из файла /// /// Путь и имя файла - /// true - загрузка прошла успешно, false - ошибка при загрузке данных - public bool LoadData(string filename) + public void LoadData(string filename) { if (!File.Exists(filename)) { - return false; + throw new FileNotFoundException("Файл не существует"); } using (StreamReader sr = new(filename)) @@ -168,12 +166,12 @@ public class StorageCollection if (line == null || line.Length == 0) { - return false; + throw new FileFormatException("В файле нет данных"); } if (!line.Equals(_collectionKey)) { //если нет такой записи, то это не те данные - return false; + throw new FileFormatException("В файле неверные данные"); } _storages.Clear(); @@ -189,7 +187,7 @@ public class StorageCollection ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionType); if (collection == null) { - return false; + throw new InvalidOperationException("Не удалось создать коллекцию"); } collection.MaxCount = Convert.ToInt32(record[2]); @@ -198,17 +196,22 @@ public class StorageCollection { if (elem?.CreateDrawningMachine() is T machine) { - if (collection.Insert(machine) == -1) + try { - return false; + if (collection.Insert(machine) == -1) + { + throw new InvalidOperationException("Объект не удалось добавить в коллекцию: " + record[3]); + } + } + catch (CollectionOverflowException ex) + { + throw new OverflowException("Коллекция переполнена", ex); } } } _storages.Add(record[0], collection); } } - - return true; } /// diff --git a/ProjectCar/ProjectCar/Exceptions/CollectionOverflowException.cs b/ProjectCar/ProjectCar/Exceptions/CollectionOverflowException.cs new file mode 100644 index 0000000..fac75e9 --- /dev/null +++ b/ProjectCar/ProjectCar/Exceptions/CollectionOverflowException.cs @@ -0,0 +1,21 @@ +using System.Runtime.Serialization; + +namespace ProjectGasMachine.Exceptions; + +/// +/// Класс, описывающий ошибку переполнения коллекции +/// +[Serializable] + +public class CollectionOverflowException : ApplicationException +{ + public CollectionOverflowException(int count) : base("В коллекции превышено допустимое количество: " + count) { } + + public CollectionOverflowException() : base() { } + + public CollectionOverflowException(string message) : base(message) { } + + public CollectionOverflowException(string message, Exception exception) : base(message, exception) { } + + protected CollectionOverflowException(SerializationInfo info, StreamingContext contex) : base(info, contex) { } +} diff --git a/ProjectCar/ProjectCar/Exceptions/ObjectNotFoundException.cs b/ProjectCar/ProjectCar/Exceptions/ObjectNotFoundException.cs new file mode 100644 index 0000000..aa09263 --- /dev/null +++ b/ProjectCar/ProjectCar/Exceptions/ObjectNotFoundException.cs @@ -0,0 +1,21 @@ +using System.Runtime.Serialization; + +namespace ProjectGasMachine.Exceptions; + +/// +/// Класс, описывающий ошибку, что по указанной позиции нет элемента +/// +[Serializable] + +internal class ObjectNotFoundException : ApplicationException +{ + public ObjectNotFoundException(int i) : base("Не найден объект по позиции " + i) { } + + public ObjectNotFoundException() : base() { } + + public ObjectNotFoundException(string message) : base(message) { } + + public ObjectNotFoundException(string message, Exception exception) : base(message, exception) { } + + protected ObjectNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { } +} diff --git a/ProjectCar/ProjectCar/Exceptions/PositionOutOfCollectionException.cs b/ProjectCar/ProjectCar/Exceptions/PositionOutOfCollectionException.cs new file mode 100644 index 0000000..55d4303 --- /dev/null +++ b/ProjectCar/ProjectCar/Exceptions/PositionOutOfCollectionException.cs @@ -0,0 +1,22 @@ +using System.Runtime.Serialization; + + +namespace ProjectGasMachine.Exceptions; + +/// +/// Класс, описывающий ошибку выхода за границы коллекции +/// +[Serializable] + +internal class PositionOutOfCollectionException : ApplicationException +{ + public PositionOutOfCollectionException(int i) : base("Выход за границы коллекции. Позиция " + i) { } + + public PositionOutOfCollectionException() : base() { } + + public PositionOutOfCollectionException(string message) : base(message) { } + + public PositionOutOfCollectionException(string message, Exception exception) : base(message, exception) { } + + protected PositionOutOfCollectionException(SerializationInfo info, StreamingContext contex) : base(info, contex) { } +} diff --git a/ProjectCar/ProjectCar/FormGasMachineCollection.Designer.cs b/ProjectCar/ProjectCar/FormGasMachineCollection.Designer.cs index c01bcbd..b27ca9e 100644 --- a/ProjectCar/ProjectCar/FormGasMachineCollection.Designer.cs +++ b/ProjectCar/ProjectCar/FormGasMachineCollection.Designer.cs @@ -66,9 +66,9 @@ groupBoxTools.Controls.Add(panelStorage); groupBoxTools.Controls.Add(comboBoxSelectorCompany); groupBoxTools.Dock = DockStyle.Right; - groupBoxTools.Location = new Point(727, 24); + groupBoxTools.Location = new Point(780, 24); groupBoxTools.Name = "groupBoxTools"; - groupBoxTools.Size = new Size(196, 519); + groupBoxTools.Size = new Size(196, 534); groupBoxTools.TabIndex = 0; groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; @@ -82,7 +82,7 @@ panelCompanyTools.Controls.Add(buttonGoToCheck); panelCompanyTools.Dock = DockStyle.Bottom; panelCompanyTools.Enabled = false; - panelCompanyTools.Location = new Point(3, 323); + panelCompanyTools.Location = new Point(3, 338); panelCompanyTools.Name = "panelCompanyTools"; panelCompanyTools.Size = new Size(190, 193); panelCompanyTools.TabIndex = 9; @@ -249,7 +249,7 @@ pictureBox.Dock = DockStyle.Fill; pictureBox.Location = new Point(0, 24); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(727, 519); + pictureBox.Size = new Size(780, 534); pictureBox.TabIndex = 3; pictureBox.TabStop = false; // @@ -258,7 +258,7 @@ menuStrip.Items.AddRange(new ToolStripItem[] { FileToolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; - menuStrip.Size = new Size(923, 24); + menuStrip.Size = new Size(976, 24); menuStrip.TabIndex = 4; menuStrip.Text = "menuStrip"; // @@ -297,7 +297,7 @@ // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(923, 543); + ClientSize = new Size(976, 558); Controls.Add(pictureBox); Controls.Add(groupBoxTools); Controls.Add(menuStrip); diff --git a/ProjectCar/ProjectCar/FormGasMachineCollection.cs b/ProjectCar/ProjectCar/FormGasMachineCollection.cs index f833233..f1fcd82 100644 --- a/ProjectCar/ProjectCar/FormGasMachineCollection.cs +++ b/ProjectCar/ProjectCar/FormGasMachineCollection.cs @@ -1,5 +1,7 @@ -using ProjectGasMachine.CollectionGenericObjects; +using Microsoft.Extensions.Logging; +using ProjectGasMachine.CollectionGenericObjects; using ProjectGasMachine.Drawnings; +using ProjectGasMachine.Exceptions; using static System.Windows.Forms.VisualStyles.VisualStyleElement.TrackBar; namespace ProjectGasMachine @@ -19,13 +21,19 @@ namespace ProjectGasMachine /// private AbstractCompany? _company = null; + /// + /// Логер + /// + private readonly ILogger _logger; + /// /// конструктор /// - public FormGasMachineCollection() + public FormGasMachineCollection(ILogger logger) { InitializeComponent(); _storageCollection = new(); + _logger = logger; } /// @@ -43,19 +51,24 @@ namespace ProjectGasMachine /// private void SetMachine(DrawningMachine? machine) { - if (_company == null || machine == null) + try { - return; + if (_company == null || machine == null) + { + return; + } + if (_company + machine != -1) + { + MessageBox.Show("Объект добавлен"); + _logger.LogInformation($"Добавлен объект {machine.GetDataForSave()}"); + pictureBox.Image = _company.Show(); + } } - if (_company + machine != -1) + catch (CollectionOverflowException ex) { - MessageBox.Show("Объект добавлен"); - pictureBox.Image = _company.Show(); - } - else - { - MessageBox.Show("Не удалось добавить объект"); + MessageBox.Show(ex.Message); + _logger.LogWarning($"Ошибка: {ex.Message}"); } } @@ -93,15 +106,25 @@ namespace ProjectGasMachine return; } - int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_company - pos != null) + try { - MessageBox.Show("Объект удален"); - pictureBox.Image = _company.Show(); + int pos = Convert.ToInt32(maskedTextBoxPosition.Text); + if (_company - pos != null) + { + MessageBox.Show("Объект удален"); + _logger.LogInformation($"Удален объект по позиции {pos}"); + pictureBox.Image = _company.Show(); + } } - else + catch (ObjectNotFoundException ex) { - MessageBox.Show("Не удалось удалить объект"); + MessageBox.Show(ex.Message); + _logger.LogError($"Ошибка: {ex.Message}"); + } + catch (PositionOutOfCollectionException ex) + { + MessageBox.Show(ex.Message); + _logger.LogError($"Ошибка: {ex.Message}"); } } @@ -167,6 +190,7 @@ namespace ProjectGasMachine if (string.IsNullOrEmpty(textBoxCollectionName.Text) || (!radioButtonList.Checked && !radioButtonMassive.Checked)) { MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + _logger.LogError("Ошибка: Заполнены не все данные для добавления коллекции"); return; } @@ -181,6 +205,7 @@ namespace ProjectGasMachine } _storageCollection.AddCollection(textBoxCollectionName.Text, collectionType); + _logger.LogInformation($"Добавлена коллекция: {textBoxCollectionName.Text} типа: {collectionType}"); RerfreshListBoxItems(); } @@ -202,6 +227,7 @@ namespace ProjectGasMachine return; } _storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString()); + _logger.LogInformation($"Удалена коллекция: {listBoxCollection.SelectedItem.ToString()}"); RerfreshListBoxItems(); } @@ -260,13 +286,16 @@ namespace ProjectGasMachine { if (saveFileDialog.ShowDialog() == DialogResult.OK) { - if (_storageCollection.SaveData(saveFileDialog.FileName)) + try { + _storageCollection.SaveData(saveFileDialog.FileName); MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + _logger.LogInformation("Сохранение в файл: {filename}", saveFileDialog.FileName); } - else + catch (Exception ex) { - MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + _logger.LogError("Ошибка: {Message}", ex.Message); } } } @@ -280,14 +309,17 @@ namespace ProjectGasMachine { if (openFileDialog.ShowDialog() == DialogResult.OK) { - if (_storageCollection.LoadData(openFileDialog.FileName)) + try { + _storageCollection.LoadData(openFileDialog.FileName); MessageBox.Show("Загрузка прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); RerfreshListBoxItems(); + _logger.LogInformation("Загрузка из фала: {filename}", openFileDialog.FileName); } - else + catch (Exception ex) { MessageBox.Show("Не загрузилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + _logger.LogError("Ошибка: {Message}", ex.Message); } } } diff --git a/ProjectCar/ProjectCar/FormGasMachineCollection.resx b/ProjectCar/ProjectCar/FormGasMachineCollection.resx index 8b1dfa1..e8f33d6 100644 --- a/ProjectCar/ProjectCar/FormGasMachineCollection.resx +++ b/ProjectCar/ProjectCar/FormGasMachineCollection.resx @@ -126,4 +126,7 @@ 261, 17 + + 60 + \ No newline at end of file diff --git a/ProjectCar/ProjectCar/Program.cs b/ProjectCar/ProjectCar/Program.cs index 0c06c51..b6b2987 100644 --- a/ProjectCar/ProjectCar/Program.cs +++ b/ProjectCar/ProjectCar/Program.cs @@ -1,3 +1,8 @@ +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Serilog; + namespace ProjectGasMachine { internal static class Program @@ -11,7 +16,26 @@ namespace ProjectGasMachine // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormGasMachineCollection()); + + ServiceCollection services = new(); + ConfigureServices(services); + using ServiceProvider serviceProvider = services.BuildServiceProvider(); + Application.Run(serviceProvider.GetRequiredService()); + } + private static void ConfigureServices(ServiceCollection services) + { + services + .AddSingleton() + .AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + var config = new ConfigurationBuilder() + .AddJsonFile("serilogConfig.json", optional: false, reloadOnChange: true) + .Build(); + option.AddSerilog(Log.Logger = new LoggerConfiguration() + .ReadFrom.Configuration(config) + .CreateLogger()); + }); } } } \ No newline at end of file diff --git a/ProjectCar/ProjectCar/ProjectGasMachine.csproj b/ProjectCar/ProjectCar/ProjectGasMachine.csproj index 8b53cc9..ea6647e 100644 --- a/ProjectCar/ProjectCar/ProjectGasMachine.csproj +++ b/ProjectCar/ProjectCar/ProjectGasMachine.csproj @@ -13,6 +13,18 @@ + + + + + + + + + + + + True @@ -28,4 +40,10 @@ + + + Always + + + \ No newline at end of file diff --git a/ProjectCar/ProjectCar/serilogConfig.json b/ProjectCar/ProjectCar/serilogConfig.json new file mode 100644 index 0000000..4e8d9cb --- /dev/null +++ b/ProjectCar/ProjectCar/serilogConfig.json @@ -0,0 +1,25 @@ +{ + "AllowedHosts": "*", + "Serilog": { + "Using": [ "Serilog.Sinks.File", "Serilog.Sinks.Console" ], + "MinimumLevel": { + "Default": "Information", + "Override": { + "Microsoft": "Warning", + "System": "Warning" + } + }, + "Enrich": [ "FromLogContext", "WithMachineName", "WithProcessId", "WithThreadId" ], + "WriteTo": [ + { "Name": "Console" }, + { + "Name": "File", + "Args": { + "path": "D:\\12121212121212\\log.txt", + "rollingInterval": "Day", + "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.ffff} | {Level:u} | {SourceContext} | {Message:1j}{NewLine}{Exception}" + } + } + ] + } +} \ No newline at end of file diff --git a/log20240506.txt b/log20240506.txt new file mode 100644 index 0000000..a36af2d --- /dev/null +++ b/log20240506.txt @@ -0,0 +1,115 @@ +2024-05-06 13:50:38.0960 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлена коллекция: wdfsd типа: Massive +2024-05-06 13:50:45.0712 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:52:46.9056 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлена коллекция: asdasd типа: Massive +2024-05-06 13:52:53.2026 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityGas:100:100:White +2024-05-06 13:53:05.3830 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:Yellow:Black:True:True +2024-05-06 13:53:08.7522 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:53:11.2964 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityGas:100:100:White +2024-05-06 13:53:14.4637 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:53:17.1079 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:53:19.7608 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:53:22.5222 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:53:25.3510 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:53:28.0964 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:53:30.5042 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:53:33.2906 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityGas:100:100:White +2024-05-06 13:53:35.6313 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:53:38.0709 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:53:40.3740 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:53:42.4957 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:53:44.7109 | WARNING | ProjectGasMachine.FormGasMachineCollection | Ошибка: В коллекции превышено допустимое количество: 16 +2024-05-06 13:53:53.7278 | WARNING | ProjectGasMachine.FormGasMachineCollection | Ошибка: В коллекции превышено допустимое количество: 16 +2024-05-06 13:54:35.9225 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлена коллекция: asdasd типа: Massive +2024-05-06 13:54:44.3352 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:55:10.2488 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлена коллекция: sdfds типа: Massive +2024-05-06 13:55:16.2229 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:55:27.1682 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлена коллекция: sdfsd типа: Massive +2024-05-06 13:55:31.4106 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:55:39.1043 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:55:40.9155 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:55:43.1087 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:55:45.4250 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:55:48.4582 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:55:50.7252 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:55:52.9109 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:55:55.2532 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:55:59.0320 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:56:02.1593 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityGas:100:100:White +2024-05-06 13:56:04.2869 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:56:06.5567 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:56:09.8771 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:56:12.4443 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:56:14.9596 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:56:17.6805 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:56:20.5141 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:56:23.1449 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:56:45.5929 | ERROR | ProjectGasMachine.FormGasMachineCollection | Ошибка: Заполнены не все данные для добавления коллекции +2024-05-06 13:56:46.5025 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлена коллекция: sad типа: Massive +2024-05-06 13:56:53.2586 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:56:55.7631 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:56:57.8691 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:57:01.2188 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:57:04.0249 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:57:06.6292 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:57:09.2126 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:57:11.7062 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:57:13.7471 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:57:15.6920 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:57:17.8150 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:57:19.8565 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityGas:100:100:White +2024-05-06 13:57:22.1338 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:57:24.0477 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:57:26.0287 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:57:28.3811 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:57:30.3505 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:57:32.5450 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:57:34.8838 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:57:38.7496 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:57:47.5191 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлена коллекция: sdfsd типа: Massive +2024-05-06 13:57:52.4258 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:57:55.4085 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityGas:100:100:White +2024-05-06 13:57:57.5999 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:58:00.1042 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:58:02.1610 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:58:04.0693 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:58:05.8936 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:58:07.9004 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:58:09.9071 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:58:12.3657 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:58:14.5239 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:58:16.3365 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:58:18.1844 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:58:20.6436 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:58:22.4090 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:58:24.4849 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:58:26.1952 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:58:28.1021 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:58:31.1549 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 13:59:55.1832 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлена коллекция: sadf типа: Massive +2024-05-06 14:00:02.6252 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 14:00:05.2891 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 14:03:43.6959 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлена коллекция: sdfsd типа: Massive +2024-05-06 14:04:19.8215 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлена коллекция: sdf типа: Massive +2024-05-06 14:05:01.4798 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлена коллекция: asdas типа: Massive +2024-05-06 14:05:36.6718 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлена коллекция: asds типа: Massive +2024-05-06 14:05:41.8552 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityGas:100:100:White +2024-05-06 14:05:44.5970 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 14:05:47.1913 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 14:05:49.3825 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 14:05:51.5111 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 14:05:54.0639 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 14:05:56.4355 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 14:05:58.7069 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 14:06:01.5593 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 14:06:03.5395 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 14:06:05.3429 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 14:06:07.8284 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 14:06:10.7956 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 14:06:12.8900 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 14:06:14.7068 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 14:06:16.9257 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 14:06:19.7250 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 14:06:22.3775 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:White:Black:False:False +2024-05-06 14:06:26.5022 | WARNING | ProjectGasMachine.FormGasMachineCollection | Ошибка: В коллекции превышено допустимое количество: 18 +2024-05-06 14:06:35.2824 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Удален объект по позиции 6 +2024-05-06 14:06:43.4500 | ERROR | ProjectGasMachine.FormGasMachineCollection | Ошибка: Не найден объект по позиции 6