From e1c1dd5284fdb063ca5a4bc28cd4f188626e8024 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=90=D0=BB=D0=B5=D0=B9?= =?UTF-8?q?=D0=BA=D0=B8=D0=BD?= Date: Sat, 26 Nov 2022 14:07:18 +0400 Subject: [PATCH 1/4] =?UTF-8?q?=D0=93=D0=B5=D0=BD=D0=B5=D1=80=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AirBomber/AirBomberNotFoundException.cs | 19 ++++++++++ .../AirBomber/FormMapWithSetAirBomber.cs | 37 +++++++++++++------ AirBomber/AirBomber/MapsCollection.cs | 10 ++--- AirBomber/AirBomber/SetAirBomberGeneric.cs | 10 ++++- .../AirBomber/StorageOverflowException.cs | 19 ++++++++++ 5 files changed, 75 insertions(+), 20 deletions(-) create mode 100644 AirBomber/AirBomber/AirBomberNotFoundException.cs create mode 100644 AirBomber/AirBomber/StorageOverflowException.cs diff --git a/AirBomber/AirBomber/AirBomberNotFoundException.cs b/AirBomber/AirBomber/AirBomberNotFoundException.cs new file mode 100644 index 0000000..7e674a9 --- /dev/null +++ b/AirBomber/AirBomber/AirBomberNotFoundException.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 AirBomber +{ + [Serializable] + internal class AirBomberNotFoundException : ApplicationException + { + public AirBomberNotFoundException() : base() { } + public AirBomberNotFoundException(int i) : base($"Не найден объект по позиции {i}") { } + public AirBomberNotFoundException(string message) : base(message) { } + public AirBomberNotFoundException(string message, Exception exception) : base (message, exception) { } + protected AirBomberNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { } + } +} diff --git a/AirBomber/AirBomber/FormMapWithSetAirBomber.cs b/AirBomber/AirBomber/FormMapWithSetAirBomber.cs index 2aed3ef..5f11999 100644 --- a/AirBomber/AirBomber/FormMapWithSetAirBomber.cs +++ b/AirBomber/AirBomber/FormMapWithSetAirBomber.cs @@ -93,14 +93,25 @@ namespace AirBomber 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 + { + MessageBox.Show("Не удалось удалить объект"); + } } - else + catch(AirBomberNotFoundException ex) { - MessageBox.Show("Не удалось удалить объект"); + MessageBox.Show($"Ошибка удаления: {ex.Message}"); + } + catch (Exception ex) + { + MessageBox.Show($"Неизвестная ошибка: {ex.Message}"); } } @@ -187,13 +198,14 @@ namespace AirBomber { 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); ; ; } } } @@ -202,15 +214,16 @@ namespace AirBomber { if (openFileDialog.ShowDialog() == DialogResult.OK) { - if (_mapsCollection.LoadData(openFileDialog.FileName)) + try { - MessageBox.Show("Загрузка прошла успешно", "Результат", + _mapsCollection.LoadData(openFileDialog.FileName); + MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); ReloadMaps(); } - else + catch(Exception ex) { - MessageBox.Show("Не загрузилось", "Результат", + MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); } } diff --git a/AirBomber/AirBomber/MapsCollection.cs b/AirBomber/AirBomber/MapsCollection.cs index f5868cd..94bef9b 100644 --- a/AirBomber/AirBomber/MapsCollection.cs +++ b/AirBomber/AirBomber/MapsCollection.cs @@ -45,7 +45,7 @@ namespace AirBomber } } - public bool SaveData(string filename) + public void SaveData(string filename) { if (File.Exists(filename)) { @@ -60,14 +60,13 @@ namespace AirBomber separatorData)}{Environment.NewLine}"); } } - return true; } - public bool LoadData(string filename) + public void LoadData(string filename) { if (!File.Exists(filename)) { - return false; + throw new Exception("Файл не найден"); } string bufferTextFromFile = ""; using (StreamReader sr = new(filename)) @@ -80,7 +79,7 @@ namespace AirBomber { if (!str.Contains("MapsCollection")) { - return false; + throw new Exception("Формат данных в файлен не правильный"); } else { @@ -111,7 +110,6 @@ namespace AirBomber } } } - return true; } } } diff --git a/AirBomber/AirBomber/SetAirBomberGeneric.cs b/AirBomber/AirBomber/SetAirBomberGeneric.cs index db6bec4..0651605 100644 --- a/AirBomber/AirBomber/SetAirBomberGeneric.cs +++ b/AirBomber/AirBomber/SetAirBomberGeneric.cs @@ -30,7 +30,7 @@ namespace AirBomber { if (position < 0 || position > _maxCount) { - return -1; + throw new StorageOverflowException(_maxCount); } _places.Insert(position, airBomber); return position; @@ -40,10 +40,16 @@ namespace AirBomber { if (position < 0 || position > _maxCount) { - return null; + throw new StorageOverflowException(_maxCount); } + T elem = _places[position]; _places[position] = null; + + if (elem == null) + { + throw new AirBomberNotFoundException(position); + } return elem; } diff --git a/AirBomber/AirBomber/StorageOverflowException.cs b/AirBomber/AirBomber/StorageOverflowException.cs new file mode 100644 index 0000000..a619a5a --- /dev/null +++ b/AirBomber/AirBomber/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 AirBomber +{ + [Serializable] + internal class StorageOverflowException : ApplicationException + { + public StorageOverflowException(int count) : base($"В наборе превышено допустимое количество: {count}") { } + public StorageOverflowException() : base() { } + public StorageOverflowException(string message) : base(message) { } + public StorageOverflowException(string message, Exception innerException) : base(message, innerException) { } + protected StorageOverflowException(SerializationInfo info, StreamingContext contex) : base(info, contex) { } + } +} -- 2.25.1 From 1721b0d06091be808ba131aa8eba28a2d7b8f987 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=90=D0=BB=D0=B5=D0=B9?= =?UTF-8?q?=D0=BA=D0=B8=D0=BD?= Date: Sat, 26 Nov 2022 14:57:23 +0400 Subject: [PATCH 2/4] =?UTF-8?q?=D0=9B=D0=BE=D0=B3=D0=B8=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/AirBomber.csproj | 17 ++++++++++++++ .../AirBomber/FormMapWithSetAirBomber.cs | 9 ++++++-- AirBomber/AirBomber/Program.cs | 22 ++++++++++++++++++- AirBomber/AirBomber/nlog.config | 13 +++++++++++ 4 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 AirBomber/AirBomber/nlog.config diff --git a/AirBomber/AirBomber/AirBomber.csproj b/AirBomber/AirBomber/AirBomber.csproj index ad1bb7a..f7fda9e 100644 --- a/AirBomber/AirBomber/AirBomber.csproj +++ b/AirBomber/AirBomber/AirBomber.csproj @@ -16,6 +16,23 @@ preview + + + + + + + Always + + + + + + + + + + True diff --git a/AirBomber/AirBomber/FormMapWithSetAirBomber.cs b/AirBomber/AirBomber/FormMapWithSetAirBomber.cs index 5f11999..9b21103 100644 --- a/AirBomber/AirBomber/FormMapWithSetAirBomber.cs +++ b/AirBomber/AirBomber/FormMapWithSetAirBomber.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 AirBomber private readonly MapsCollection _mapsCollection; - public FormMapWithSetAirBomber() + private readonly ILogger _logger; + + public FormMapWithSetAirBomber(ILogger logger) { InitializeComponent(); + _logger = logger; _mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height); comboBoxSelectorMap.Items.Clear(); foreach (var elem in _mapsDict) @@ -173,6 +177,7 @@ namespace AirBomber } _mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]); ReloadMaps(); + _logger.LogInformation($"Добавлена карта: {textBoxNewMapName.Text}"); } private void ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e) diff --git a/AirBomber/AirBomber/Program.cs b/AirBomber/AirBomber/Program.cs index 4c9e3e7..d08f98e 100644 --- a/AirBomber/AirBomber/Program.cs +++ b/AirBomber/AirBomber/Program.cs @@ -1,3 +1,8 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using System.ServiceProcess; + namespace AirBomber { internal static class Program @@ -11,7 +16,22 @@ namespace AirBomber // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormMapWithSetAirBomber()); + var services = new ServiceCollection(); + 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); + option.AddNLog("nlog.config"); + }); } } } \ No newline at end of file diff --git a/AirBomber/AirBomber/nlog.config b/AirBomber/AirBomber/nlog.config new file mode 100644 index 0000000..6d5e25e --- /dev/null +++ b/AirBomber/AirBomber/nlog.config @@ -0,0 +1,13 @@ + + + + + + + + + + + \ No newline at end of file -- 2.25.1 From e367b850729c9de4d516c2535943fdd0e1fc1f4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=90=D0=BB=D0=B5=D0=B9?= =?UTF-8?q?=D0=BA=D0=B8=D0=BD?= Date: Sat, 26 Nov 2022 16:35:32 +0400 Subject: [PATCH 3/4] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=207=20?= =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BA?= =?UTF-8?q?=D1=83.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/AirBomber.csproj | 3 ++ .../AirBomber/FormMapWithSetAirBomber.cs | 44 +++++++++++++++---- AirBomber/AirBomber/MapsCollection.cs | 6 +-- AirBomber/AirBomber/Program.cs | 5 ++- AirBomber/AirBomber/SetAirBomberGeneric.cs | 10 +++-- AirBomber/AirBomber/nlog.config | 2 +- 6 files changed, 54 insertions(+), 16 deletions(-) diff --git a/AirBomber/AirBomber/AirBomber.csproj b/AirBomber/AirBomber/AirBomber.csproj index f7fda9e..d5ebab9 100644 --- a/AirBomber/AirBomber/AirBomber.csproj +++ b/AirBomber/AirBomber/AirBomber.csproj @@ -31,6 +31,9 @@ + + + diff --git a/AirBomber/AirBomber/FormMapWithSetAirBomber.cs b/AirBomber/AirBomber/FormMapWithSetAirBomber.cs index 9b21103..61ec157 100644 --- a/AirBomber/AirBomber/FormMapWithSetAirBomber.cs +++ b/AirBomber/AirBomber/FormMapWithSetAirBomber.cs @@ -71,14 +71,28 @@ namespace AirBomber { return; } - if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawningObjectBomber(airBomber) > -1) + try { - MessageBox.Show("Объект добавлен"); - pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawningObjectBomber(airBomber) != -1) + { + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + _logger.LogInformation($"Добавлен объект: {airBomber} на карте: {listBoxMaps.SelectedItem}"); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } } - 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}"); } } @@ -102,6 +116,7 @@ namespace AirBomber if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null) { MessageBox.Show("Объект удален"); + _logger.LogInformation($"Удален объект с позиции: [{pos}] на карте: {listBoxMaps.SelectedItem}"); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } else @@ -111,10 +126,17 @@ namespace AirBomber } catch(AirBomberNotFoundException ex) { + _logger.LogWarning($"Ошибка отсутствия объекта на позиции: [{pos}] при его удалении: {ex.Message}"); MessageBox.Show($"Ошибка удаления: {ex.Message}"); } - catch (Exception ex) + catch (StorageOverflowException ex) { + _logger.LogWarning($"Ошибка при удалении объекта на позиции: [{pos}] выходя за рамки поля: {ex.Message}"); + MessageBox.Show($"Превышение размерности: {ex.Message}"); + } + catch(Exception ex) + { + _logger.LogWarning($"Неизвестная ошибка при удалении объекта на позиции: [{pos}] : {ex.Message}"); MessageBox.Show($"Неизвестная ошибка: {ex.Message}"); } } @@ -126,6 +148,7 @@ namespace AirBomber return; } pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + _logger.LogInformation($"Переход в хранилище: {listBoxMaps.SelectedItem}"); } private void ButtonShowOnMap_Click(object sender, EventArgs e) @@ -135,6 +158,7 @@ namespace AirBomber return; } pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap(); + _logger.LogInformation($"Переход на карту: {listBoxMaps.SelectedItem}"); } private void ButtonMove_Click(object sender, EventArgs e) @@ -193,10 +217,10 @@ namespace AirBomber } if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { + _logger.LogInformation($"Удалена карта: {listBoxMaps.SelectedItem}"); _mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty); ReloadMaps(); } - } private void SaveToolStripMenuItem_Click(object sender, EventArgs e) @@ -206,10 +230,12 @@ namespace AirBomber 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); ; ; } } @@ -222,12 +248,14 @@ namespace AirBomber try { _mapsCollection.LoadData(openFileDialog.FileName); - MessageBox.Show("Загрузка прошла успешно", "Результат", + _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/AirBomber/AirBomber/MapsCollection.cs b/AirBomber/AirBomber/MapsCollection.cs index 94bef9b..7110879 100644 --- a/AirBomber/AirBomber/MapsCollection.cs +++ b/AirBomber/AirBomber/MapsCollection.cs @@ -65,8 +65,8 @@ namespace AirBomber public void LoadData(string filename) { if (!File.Exists(filename)) - { - throw new Exception("Файл не найден"); + { + throw new FileNotFoundException("Файл не найден"); } string bufferTextFromFile = ""; using (StreamReader sr = new(filename)) @@ -79,7 +79,7 @@ namespace AirBomber { if (!str.Contains("MapsCollection")) { - throw new Exception("Формат данных в файлен не правильный"); + throw new FormatException("Формат данных в файле не правильный"); } else { diff --git a/AirBomber/AirBomber/Program.cs b/AirBomber/AirBomber/Program.cs index d08f98e..6c5fd32 100644 --- a/AirBomber/AirBomber/Program.cs +++ b/AirBomber/AirBomber/Program.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; +using Serilog; using System.ServiceProcess; namespace AirBomber @@ -26,11 +27,13 @@ namespace AirBomber private static void ConfigureServices(ServiceCollection services) { + var serilogLogger = new LoggerConfiguration().WriteTo.File("seriallog.txt").CreateLogger(); + services.AddSingleton() .AddLogging(option => { option.SetMinimumLevel(LogLevel.Information); - option.AddNLog("nlog.config"); + option.AddSerilog(logger: serilogLogger, dispose: true); }); } } diff --git a/AirBomber/AirBomber/SetAirBomberGeneric.cs b/AirBomber/AirBomber/SetAirBomberGeneric.cs index 0651605..4cac74d 100644 --- a/AirBomber/AirBomber/SetAirBomberGeneric.cs +++ b/AirBomber/AirBomber/SetAirBomberGeneric.cs @@ -28,7 +28,11 @@ namespace AirBomber public int Insert(T airBomber, int position) { - if (position < 0 || position > _maxCount) + if (_places.Count >= _maxCount) + { + throw new StorageOverflowException(_maxCount); + } + if (position < 0 || position >= _maxCount) { throw new StorageOverflowException(_maxCount); } @@ -38,13 +42,13 @@ namespace AirBomber public T Remove(int position) { - if (position < 0 || position > _maxCount) + if (position < 0 || position >= _maxCount) { throw new StorageOverflowException(_maxCount); } T elem = _places[position]; - _places[position] = null; + _places.Remove(elem); if (elem == null) { diff --git a/AirBomber/AirBomber/nlog.config b/AirBomber/AirBomber/nlog.config index 6d5e25e..16c12e3 100644 --- a/AirBomber/AirBomber/nlog.config +++ b/AirBomber/AirBomber/nlog.config @@ -4,7 +4,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" autoReload="true" internalLogLevel="Info"> - + -- 2.25.1 From a4a89b5f215da3b3b8c3806a48c5bb12a909e45e Mon Sep 17 00:00:00 2001 From: 1yuee Date: Wed, 30 Nov 2022 10:24:06 +0400 Subject: [PATCH 4/4] =?UTF-8?q?7=20=D0=BB=D0=B0=D0=B1=D1=83=20=D1=81=D0=B4?= =?UTF-8?q?=D0=B0=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/AirBomber.csproj | 9 ++++++--- AirBomber/AirBomber/FormAirBomberConfig.cs | 4 +++- AirBomber/AirBomber/FormMapWithSetAirBomber.cs | 2 +- AirBomber/AirBomber/MapsCollection.cs | 3 +-- AirBomber/AirBomber/Program.cs | 13 +++++++++---- AirBomber/AirBomber/nlog.config | 13 ------------- AirBomber/AirBomber/serilog.json | 17 +++++++++++++++++ 7 files changed, 37 insertions(+), 24 deletions(-) delete mode 100644 AirBomber/AirBomber/nlog.config create mode 100644 AirBomber/AirBomber/serilog.json diff --git a/AirBomber/AirBomber/AirBomber.csproj b/AirBomber/AirBomber/AirBomber.csproj index d5ebab9..9f633c8 100644 --- a/AirBomber/AirBomber/AirBomber.csproj +++ b/AirBomber/AirBomber/AirBomber.csproj @@ -17,22 +17,25 @@ - + - + Always + + + - + diff --git a/AirBomber/AirBomber/FormAirBomberConfig.cs b/AirBomber/AirBomber/FormAirBomberConfig.cs index 51e0803..af7293e 100644 --- a/AirBomber/AirBomber/FormAirBomberConfig.cs +++ b/AirBomber/AirBomber/FormAirBomberConfig.cs @@ -12,9 +12,10 @@ namespace AirBomber { public partial class FormAirBomberConfig : Form { - DrawningBomber _airBomber = null; + static DrawningBomber _airBomber = null; private Action EventAddAirBomber; + public FormAirBomberConfig() { InitializeComponent(); @@ -51,6 +52,7 @@ namespace AirBomber } } + private void LabelObject_MouseDown(object sender, MouseEventArgs e) { (sender as Label).DoDragDrop((sender as Label).Name, DragDropEffects.Move | DragDropEffects.Copy); diff --git a/AirBomber/AirBomber/FormMapWithSetAirBomber.cs b/AirBomber/AirBomber/FormMapWithSetAirBomber.cs index 61ec157..d014f00 100644 --- a/AirBomber/AirBomber/FormMapWithSetAirBomber.cs +++ b/AirBomber/AirBomber/FormMapWithSetAirBomber.cs @@ -45,7 +45,7 @@ namespace AirBomber for (int i = 0; i < _mapsCollection.Keys.Count; i++) { listBoxMaps.Items.Add(_mapsCollection.Keys[i]); - } + } if (listBoxMaps.Items.Count > 0 && (index == -1 || index >= listBoxMaps.Items.Count)) { diff --git a/AirBomber/AirBomber/MapsCollection.cs b/AirBomber/AirBomber/MapsCollection.cs index 7110879..d092ec0 100644 --- a/AirBomber/AirBomber/MapsCollection.cs +++ b/AirBomber/AirBomber/MapsCollection.cs @@ -56,8 +56,7 @@ namespace AirBomber sw.Write($"MapsCollection{Environment.NewLine}"); foreach (var storage in _mapStorages) { - sw.Write($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, - separatorData)}{Environment.NewLine}"); + sw.Write($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}{Environment.NewLine}"); } } } diff --git a/AirBomber/AirBomber/Program.cs b/AirBomber/AirBomber/Program.cs index 6c5fd32..d44e7a1 100644 --- a/AirBomber/AirBomber/Program.cs +++ b/AirBomber/AirBomber/Program.cs @@ -1,6 +1,6 @@ +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using NLog.Extensions.Logging; using Serilog; using System.ServiceProcess; @@ -27,13 +27,18 @@ namespace AirBomber private static void ConfigureServices(ServiceCollection services) { - var serilogLogger = new LoggerConfiguration().WriteTo.File("seriallog.txt").CreateLogger(); - services.AddSingleton() .AddLogging(option => { + var config = new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) + .AddJsonFile("serilog.json") + .Build(); + + Log.Logger = new LoggerConfiguration().ReadFrom.Configuration(config).CreateLogger(); + option.SetMinimumLevel(LogLevel.Information); - option.AddSerilog(logger: serilogLogger, dispose: true); + option.AddSerilog(); }); } } diff --git a/AirBomber/AirBomber/nlog.config b/AirBomber/AirBomber/nlog.config deleted file mode 100644 index 16c12e3..0000000 --- a/AirBomber/AirBomber/nlog.config +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/AirBomber/AirBomber/serilog.json b/AirBomber/AirBomber/serilog.json new file mode 100644 index 0000000..7727326 --- /dev/null +++ b/AirBomber/AirBomber/serilog.json @@ -0,0 +1,17 @@ +{ + "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}" + } + } + ], + "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ] + } +} -- 2.25.1