From 3a4981999465bfd405b8cbeda6fb48cd8d8c58b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=20=D0=91=D0=BE=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Sun, 27 Nov 2022 23:12:56 +0400 Subject: [PATCH 1/8] =?UTF-8?q?=D0=AD=D1=82=D0=B0=D0=BF=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarmlyShip/WarmlyShip/FormMapWithSetShip.cs | 33 ++++++++++++------- WarmlyShip/WarmlyShip/MapsCollection.cs | 10 +++--- WarmlyShip/WarmlyShip/SetShipGeneric.cs | 3 +- .../WarmlyShip/ShipNotFoundException.cs | 19 +++++++++++ .../WarmlyShip/StorageOverflowException.cs | 19 +++++++++++ 5 files changed, 65 insertions(+), 19 deletions(-) create mode 100644 WarmlyShip/WarmlyShip/ShipNotFoundException.cs create mode 100644 WarmlyShip/WarmlyShip/StorageOverflowException.cs diff --git a/WarmlyShip/WarmlyShip/FormMapWithSetShip.cs b/WarmlyShip/WarmlyShip/FormMapWithSetShip.cs index ee87e04..b542f9a 100644 --- a/WarmlyShip/WarmlyShip/FormMapWithSetShip.cs +++ b/WarmlyShip/WarmlyShip/FormMapWithSetShip.cs @@ -127,15 +127,22 @@ namespace WarmlyShip return; } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null) + try { - MessageBox.Show("Объект удален"); - pictureBox.Image = - _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null) + { + MessageBox.Show("Объект удален"); + pictureBox.Image = + _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + } } - else + catch(ShipNotFoundException ex) { - MessageBox.Show("Не удалось удалить объект"); + MessageBox.Show($"Ошибка удаления: {ex.Message} "); + } + catch (Exception ex) + { + MessageBox.Show($"Неизвестная ошибка: {ex.Message} "); } } @@ -188,13 +195,14 @@ namespace WarmlyShip { if (saveFileDialog.ShowDialog() == DialogResult.OK) { - if (_mapsCollection.SaveData(saveFileDialog.FileName)) + try { + _mapsCollection.SaveData(saveFileDialog.FileName); MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); } - else + catch (Exception ex) { - MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } @@ -203,14 +211,15 @@ namespace WarmlyShip { if (openFileDialog.ShowDialog() == DialogResult.OK) { - if (_mapsCollection.LoadData(openFileDialog.FileName)) + try { + _mapsCollection.LoadData(openFileDialog.FileName); MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); ReloadMaps(); } - else + catch (Exception ex) { - MessageBox.Show("Не загрузилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } diff --git a/WarmlyShip/WarmlyShip/MapsCollection.cs b/WarmlyShip/WarmlyShip/MapsCollection.cs index 503080b..966ec7b 100644 --- a/WarmlyShip/WarmlyShip/MapsCollection.cs +++ b/WarmlyShip/WarmlyShip/MapsCollection.cs @@ -50,7 +50,7 @@ namespace WarmlyShip } } - public bool SaveData(string filename) + public void SaveData(string filename) { if (File.Exists(filename)) { @@ -65,14 +65,13 @@ namespace WarmlyShip sw.Write($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}{Environment.NewLine}"); } } - return true; } - public bool LoadData(string filename) + public void LoadData(string filename) { if (!File.Exists(filename)) { - return false; + throw new Exception("Файл не найден"); } using (StreamReader sr = new(filename)) { @@ -84,7 +83,7 @@ namespace WarmlyShip { if (!bufferStr.Contains("MapsCollection")) { - return false; + throw new Exception("Формат данных в файле не правильный"); } else { @@ -113,7 +112,6 @@ namespace WarmlyShip } } } - return true; } } } diff --git a/WarmlyShip/WarmlyShip/SetShipGeneric.cs b/WarmlyShip/WarmlyShip/SetShipGeneric.cs index 7d336d8..c768070 100644 --- a/WarmlyShip/WarmlyShip/SetShipGeneric.cs +++ b/WarmlyShip/WarmlyShip/SetShipGeneric.cs @@ -27,13 +27,14 @@ namespace WarmlyShip public int Insert(T ship, int position) { - if (position < 0 || position > Count || Count == _maxCount) return -1; + if (position < 0 || position > Count || Count == _maxCount) throw new StorageOverflowException(_maxCount); _places.Insert(position, ship); return position; } public T Remove(int position) { + if (position >= _maxCount || position >= _places.Count) throw new ShipNotFoundException(position); T DelElement = _places[position]; _places[position] = null; return DelElement; diff --git a/WarmlyShip/WarmlyShip/ShipNotFoundException.cs b/WarmlyShip/WarmlyShip/ShipNotFoundException.cs new file mode 100644 index 0000000..528b699 --- /dev/null +++ b/WarmlyShip/WarmlyShip/ShipNotFoundException.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; + +namespace WarmlyShip +{ + [Serializable] + internal class ShipNotFoundException : Exception + { + public ShipNotFoundException(int i) : base($"Не найден объект по позиции { i}") { } + public ShipNotFoundException() : base() { } + public ShipNotFoundException(string message) : base(message) { } + public ShipNotFoundException(string message, Exception exception) : base(message, exception) { } + protected ShipNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { } + } +} diff --git a/WarmlyShip/WarmlyShip/StorageOverflowException.cs b/WarmlyShip/WarmlyShip/StorageOverflowException.cs new file mode 100644 index 0000000..e6c922a --- /dev/null +++ b/WarmlyShip/WarmlyShip/StorageOverflowException.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; + +namespace WarmlyShip +{ + [Serializable] + internal class StorageOverflowException : Exception + { + public StorageOverflowException(int count) : base($"В наборе превышено допустимое количество: { count}") { } + public StorageOverflowException() : base() { } + public StorageOverflowException(string message) : base(message) { } + public StorageOverflowException(string message, Exception exception) : base(message, exception) { } + protected StorageOverflowException(SerializationInfo info, StreamingContext contex) : base(info, contex) { } + } +} -- 2.25.1 From deb44d61460e5a7913c0f383bde0fd908983b884 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=20=D0=91=D0=BE=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Mon, 28 Nov 2022 00:42:09 +0400 Subject: [PATCH 2/8] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarmlyShip/WarmlyShip/FormMapWithSetShip.cs | 53 ++++++++++++++++----- WarmlyShip/WarmlyShip/Program.cs | 29 +++++++++-- WarmlyShip/WarmlyShip/WarmlyShip.csproj | 8 ++++ WarmlyShip/WarmlyShip/nlog.config | 13 +++++ 4 files changed, 87 insertions(+), 16 deletions(-) create mode 100644 WarmlyShip/WarmlyShip/nlog.config diff --git a/WarmlyShip/WarmlyShip/FormMapWithSetShip.cs b/WarmlyShip/WarmlyShip/FormMapWithSetShip.cs index b542f9a..6261fb6 100644 --- a/WarmlyShip/WarmlyShip/FormMapWithSetShip.cs +++ b/WarmlyShip/WarmlyShip/FormMapWithSetShip.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.Extensions.Logging; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -23,9 +24,12 @@ namespace WarmlyShip private readonly MapsCollection _mapsCollection; - public FormMapWithSetShip() + private readonly ILogger _logger; + + public FormMapWithSetShip(ILogger logger) { InitializeComponent(); + _logger = logger; _mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height); comboBoxSelectorMap.Items.Clear(); foreach (var elem in _mapsDict) @@ -66,6 +70,7 @@ namespace WarmlyShip } _mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]); ReloadMaps(); + _logger.LogInformation($"Добавлена карта {textBoxNewMapName.Text}"); } private void ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e) @@ -81,9 +86,9 @@ namespace WarmlyShip } if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { - _mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? - string.Empty); + _mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty); ReloadMaps(); + _logger.LogInformation("Удалена карта {0}", listBoxMaps.SelectedItem?.ToString() ?? string.Empty); } } @@ -100,15 +105,24 @@ namespace WarmlyShip { return; } - - if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawningObjectShip(ship) > -1) + try { - MessageBox.Show("Объект добавлен"); - pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawningObjectShip(ship) > -1) + { + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + _logger.LogInformation($"Добавлен объект: {ship} на карте: {listBoxMaps.SelectedItem}"); + } } - else + catch (StorageOverflowException ex) { - MessageBox.Show("Не удалось добавить объект"); + _logger.LogWarning($"Ошибка переполнения при добавлении объекта: {ex.Message}"); + MessageBox.Show($"Ошибка переполнения: {ex.Message}"); + } + catch (Exception ex) + { + _logger.LogWarning($"Неизвестная ошибка при добавлении объекта: {ex.Message}"); + MessageBox.Show($"Неизвестная ошибка: {ex.Message}"); } } @@ -132,16 +146,23 @@ namespace WarmlyShip if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null) { MessageBox.Show("Объект удален"); - pictureBox.Image = - _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + _logger.LogInformation($"Удален объект с позиции: [{pos}] на карте: {listBoxMaps.SelectedItem}"); } } - catch(ShipNotFoundException ex) + catch (ShipNotFoundException ex) { + _logger.LogWarning($"Ошибка при удалении объекта на позиции: {ex.Message}"); MessageBox.Show($"Ошибка удаления: {ex.Message} "); } + catch (StorageOverflowException ex) + { + _logger.LogWarning($"Ошибка при удалении объекта на позиции: {ex.Message}"); + MessageBox.Show($"Превышение размерности: {ex.Message}"); + } catch (Exception ex) { + _logger.LogWarning($"Неизвестная ошибка при удалении объекта на позиции: {ex.Message}"); MessageBox.Show($"Неизвестная ошибка: {ex.Message} "); } } @@ -153,6 +174,7 @@ namespace WarmlyShip return; } pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + _logger.LogInformation($"Переход в хранилище: {listBoxMaps.SelectedItem}"); } private void ButtonShowOnMap_Click(object sender, EventArgs e) @@ -162,6 +184,7 @@ namespace WarmlyShip return; } pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap(); + _logger.LogInformation($"Переход на карту: {listBoxMaps.SelectedItem}"); } private void ButtonMove_Click(object sender, EventArgs e) @@ -198,10 +221,12 @@ namespace WarmlyShip try { _mapsCollection.SaveData(saveFileDialog.FileName); + _logger.LogInformation($"Карта успешно сохранена в файл: {saveFileDialog.FileName}"); MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { + _logger.LogWarning($"Не сохранилось в файл: {saveFileDialog.FileName}"); MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); } } @@ -214,11 +239,13 @@ namespace WarmlyShip try { _mapsCollection.LoadData(openFileDialog.FileName); + _logger.LogInformation($"Карта успешно загружена из файла: {openFileDialog.FileName}"); MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); ReloadMaps(); } catch (Exception ex) { + _logger.LogWarning($"Не загрузилось из файла: {openFileDialog.FileName}"); MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); } } diff --git a/WarmlyShip/WarmlyShip/Program.cs b/WarmlyShip/WarmlyShip/Program.cs index de3a3a8..6968d22 100644 --- a/WarmlyShip/WarmlyShip/Program.cs +++ b/WarmlyShip/WarmlyShip/Program.cs @@ -1,3 +1,7 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Serilog; + namespace WarmlyShip { internal static class Program @@ -11,7 +15,26 @@ namespace WarmlyShip // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormMapWithSetShip()); - } - } + var services = new ServiceCollection(); + ConfigureServices(services); + using (ServiceProvider serviceProvider = + services.BuildServiceProvider()) + { + Application.Run(serviceProvider.GetRequiredService()); + } + } + + private static void ConfigureServices(ServiceCollection services) + { + services.AddSingleton(); + + var serilogLogger = new LoggerConfiguration().WriteTo.File("log.txt").CreateLogger(); + + services.AddLogging(builder => + { + builder.SetMinimumLevel(LogLevel.Information); + builder.AddSerilog(logger: serilogLogger, dispose: true); + }); + } + } } \ No newline at end of file diff --git a/WarmlyShip/WarmlyShip/WarmlyShip.csproj b/WarmlyShip/WarmlyShip/WarmlyShip.csproj index 13ee123..edbfc03 100644 --- a/WarmlyShip/WarmlyShip/WarmlyShip.csproj +++ b/WarmlyShip/WarmlyShip/WarmlyShip.csproj @@ -8,6 +8,14 @@ enable + + + + + + + + True diff --git a/WarmlyShip/WarmlyShip/nlog.config b/WarmlyShip/WarmlyShip/nlog.config new file mode 100644 index 0000000..7164133 --- /dev/null +++ b/WarmlyShip/WarmlyShip/nlog.config @@ -0,0 +1,13 @@ + + + + + + + + + + + \ No newline at end of file -- 2.25.1 From 84f6cf46f9552defbddfcd50ecce29ce4db1c4db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=20=D0=91=D0=BE=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Wed, 30 Nov 2022 09:01:56 +0400 Subject: [PATCH 3/8] =?UTF-8?q?=D0=B4=D0=BE=D0=BF=D0=BE=D0=BB=D0=BD=D0=B8?= =?UTF-8?q?=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarmlyShip/WarmlyShip/MapsCollection.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WarmlyShip/WarmlyShip/MapsCollection.cs b/WarmlyShip/WarmlyShip/MapsCollection.cs index 966ec7b..f642942 100644 --- a/WarmlyShip/WarmlyShip/MapsCollection.cs +++ b/WarmlyShip/WarmlyShip/MapsCollection.cs @@ -71,7 +71,7 @@ namespace WarmlyShip { if (!File.Exists(filename)) { - throw new Exception("Файл не найден"); + throw new FileNotFoundException("Файл не найден"); } using (StreamReader sr = new(filename)) { @@ -83,7 +83,7 @@ namespace WarmlyShip { if (!bufferStr.Contains("MapsCollection")) { - throw new Exception("Формат данных в файле не правильный"); + throw new FormatException("Формат данных в файле не правильный"); } else { -- 2.25.1 From 02a9aee9a39a037d0bd9e0830cb2ed3e6f4df085 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=20=D0=91=D0=BE=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Wed, 30 Nov 2022 09:15:42 +0400 Subject: [PATCH 4/8] =?UTF-8?q?=D0=BF=D0=BE=D0=B4=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarmlyShip/WarmlyShip/SetShipGeneric.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WarmlyShip/WarmlyShip/SetShipGeneric.cs b/WarmlyShip/WarmlyShip/SetShipGeneric.cs index c768070..8a37607 100644 --- a/WarmlyShip/WarmlyShip/SetShipGeneric.cs +++ b/WarmlyShip/WarmlyShip/SetShipGeneric.cs @@ -36,7 +36,7 @@ namespace WarmlyShip { if (position >= _maxCount || position >= _places.Count) throw new ShipNotFoundException(position); T DelElement = _places[position]; - _places[position] = null; + _places.Remove(DelElement); return DelElement; } -- 2.25.1 From fa3f46c12c40a104dcf842864f432dc1fa09e00f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=20=D0=91=D0=BE=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Wed, 30 Nov 2022 09:34:54 +0400 Subject: [PATCH 5/8] =?UTF-8?q?=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarmlyShip/WarmlyShip/WarmlyShip.csproj | 11 +++++++++++ WarmlyShip/WarmlyShip/nlog.config | 13 ------------- WarmlyShip/WarmlyShip/serilogConfig.json | 17 +++++++++++++++++ 3 files changed, 28 insertions(+), 13 deletions(-) delete mode 100644 WarmlyShip/WarmlyShip/nlog.config create mode 100644 WarmlyShip/WarmlyShip/serilogConfig.json diff --git a/WarmlyShip/WarmlyShip/WarmlyShip.csproj b/WarmlyShip/WarmlyShip/WarmlyShip.csproj index edbfc03..316facb 100644 --- a/WarmlyShip/WarmlyShip/WarmlyShip.csproj +++ b/WarmlyShip/WarmlyShip/WarmlyShip.csproj @@ -8,10 +8,21 @@ enable + + + + + + + Always + + + + diff --git a/WarmlyShip/WarmlyShip/nlog.config b/WarmlyShip/WarmlyShip/nlog.config deleted file mode 100644 index 7164133..0000000 --- a/WarmlyShip/WarmlyShip/nlog.config +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/WarmlyShip/WarmlyShip/serilogConfig.json b/WarmlyShip/WarmlyShip/serilogConfig.json new file mode 100644 index 0000000..8272717 --- /dev/null +++ b/WarmlyShip/WarmlyShip/serilogConfig.json @@ -0,0 +1,17 @@ +{ + "Serilog": { + "Using": [ "Serilog.Sinks.File" ], + "MinimumLevel": "Information", + "WriteTo": [ + { + "Name": "File", + "Args": { + "path": "Logs/log_.log", + "rollingInterval": "Day", + "outputTemplate": "{Level:u4}: {Message:lj} [{Timestamp:HH:mm:ss.fff}]{NewLine}" + } + } + ], + "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ] + } + } \ No newline at end of file -- 2.25.1 From 9980a9395dc00ae4a7fc72f606349a6f536f2f39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=20=D0=91=D0=BE=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Wed, 30 Nov 2022 09:37:47 +0400 Subject: [PATCH 6/8] =?UTF-8?q?=D1=83=D0=B4=D0=B0=D0=BB=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BB=D0=B8=D1=88=D0=BD=D0=B8=D0=B9=20=D1=84=D0=B0=D0=B9=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarmlyShip/WarmlyShip/ShipDelegate.cs | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 WarmlyShip/WarmlyShip/ShipDelegate.cs diff --git a/WarmlyShip/WarmlyShip/ShipDelegate.cs b/WarmlyShip/WarmlyShip/ShipDelegate.cs deleted file mode 100644 index c80372b..0000000 --- a/WarmlyShip/WarmlyShip/ShipDelegate.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace WarmlyShip -{ - public delegate void ShipDelegate(DrawingWarmlyShip warmlyShip); -} -- 2.25.1 From 0a4cfe48c337ee1c4f996b4fa58ff8f286d20975 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=20=D0=91=D0=BE=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Thu, 1 Dec 2022 22:53:59 +0400 Subject: [PATCH 7/8] =?UTF-8?q?=D0=94=D0=BB=D1=8F=20pull?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarmlyShip/WarmlyShip/Program.cs | 19 ++++++++++++------- WarmlyShip/WarmlyShip/WarmlyShip.csproj | 5 +++++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/WarmlyShip/WarmlyShip/Program.cs b/WarmlyShip/WarmlyShip/Program.cs index 6968d22..8f659fc 100644 --- a/WarmlyShip/WarmlyShip/Program.cs +++ b/WarmlyShip/WarmlyShip/Program.cs @@ -26,14 +26,19 @@ namespace WarmlyShip private static void ConfigureServices(ServiceCollection services) { - services.AddSingleton(); - - var serilogLogger = new LoggerConfiguration().WriteTo.File("log.txt").CreateLogger(); - - services.AddLogging(builder => + services.AddSingleton().AddLogging(option => { - builder.SetMinimumLevel(LogLevel.Information); - builder.AddSerilog(logger: serilogLogger, dispose: true); + var configuration = new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) + .AddJsonFile(path: "appsettings.json", optional: false, reloadOnChange: true) + .Build(); + + var logger = new LoggerConfiguration() + .ReadFrom.Configuration(configuration) + .CreateLogger(); + + option.SetMinimumLevel(LogLevel.Information); + option.AddSerilog(logger); }); } } diff --git a/WarmlyShip/WarmlyShip/WarmlyShip.csproj b/WarmlyShip/WarmlyShip/WarmlyShip.csproj index 316facb..62b17eb 100644 --- a/WarmlyShip/WarmlyShip/WarmlyShip.csproj +++ b/WarmlyShip/WarmlyShip/WarmlyShip.csproj @@ -19,11 +19,16 @@ + + + + + -- 2.25.1 From 9c0a1678a05667a6a5606e630b5b3a9ed52922e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=20=D0=91=D0=BE=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Thu, 1 Dec 2022 23:00:18 +0400 Subject: [PATCH 8/8] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=20=D0=BA=20p?= =?UTF-8?q?ull?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarmlyShip/WarmlyShip/Program.cs | 3 ++- WarmlyShip/WarmlyShip/serilogConfig.json | 29 ++++++++++++------------ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/WarmlyShip/WarmlyShip/Program.cs b/WarmlyShip/WarmlyShip/Program.cs index 8f659fc..ef09eae 100644 --- a/WarmlyShip/WarmlyShip/Program.cs +++ b/WarmlyShip/WarmlyShip/Program.cs @@ -1,3 +1,4 @@ +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Serilog; @@ -30,7 +31,7 @@ namespace WarmlyShip { var configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile(path: "appsettings.json", optional: false, reloadOnChange: true) + .AddJsonFile(path: "serilogConfig.json", optional: false, reloadOnChange: true) .Build(); var logger = new LoggerConfiguration() diff --git a/WarmlyShip/WarmlyShip/serilogConfig.json b/WarmlyShip/WarmlyShip/serilogConfig.json index 8272717..3825ce1 100644 --- a/WarmlyShip/WarmlyShip/serilogConfig.json +++ b/WarmlyShip/WarmlyShip/serilogConfig.json @@ -1,17 +1,16 @@ { - "Serilog": { - "Using": [ "Serilog.Sinks.File" ], - "MinimumLevel": "Information", - "WriteTo": [ - { - "Name": "File", - "Args": { - "path": "Logs/log_.log", - "rollingInterval": "Day", - "outputTemplate": "{Level:u4}: {Message:lj} [{Timestamp:HH:mm:ss.fff}]{NewLine}" - } + "Serilog": { + "Using": [ "Serilog.Sinks.File" ], + "MinimumLevel": "Information", + "WriteTo": [ + { + "Name": "File", + "Args": { + "path": "Logs/log_.log", + "rollingInterval": "Day", + "outputTemplate": "[{Timestamp:HH:mm:ss.fff}]{Level:u4}: {Message:lj}{NewLine}{Exception}" } - ], - "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ] - } - } \ No newline at end of file + } + ] + } +} \ No newline at end of file -- 2.25.1